How do I overlap widgets with the Tkinter pack geometry manager?

Question!

I want to put a Canvas with an image in my window, and then I want to pack widgets on top of it, so the Canvas acts as a background.

Is it possible to have two states for the pack manager: one for one set of widgets and another for another set?



Answers

... turned out to be unworkable because I wanted to add labels and more canvases to it, but I can't find any way to make their backgrounds transparent

If it is acceptable to load an additional extension, take a look at Tkzinc. From the web site,

Tkzinc (historically called Zinc) widget is very similar to the Tk Canvas in that they both support structured graphics. Like the Canvas, Tkzinc implements items used to display graphical entities. Those items can be manipulated and bindings can be associated with them to implement interaction behaviors. But unlike the Canvas, Tkzinc can structure the items in a hierarchy, has support for scaling and rotation, clipping can be set for sub-trees of the item hierarchy, supports muti-contour curves. It also provides advanced rendering with the help of OpenGL, such as color gradient, antialiasing, transparencies and a triangles item.

I'm currently using it on a tcl project and am quite pleased with the results. Extensions for tcl, perl, and python are available.

By : erichui


I believe that Bryan's answer is probably the best general solution. However, you may also want to look at the place geometry manager. The place geometry manager lets you specify the exact size and position of the widget... which can get tedious quickly, but will get the job done.

By : erichui


Not without swapping widget trees in and out, which I don't think can be done cleanly with Tk. Other toolkits can do this a little more elegantly.

  • COM/VB/MFC can do this with an ActiveX control - you can hide/show multiple ActiveX controls in the same region. Any of the containers will let you do this by changing the child around. If you're doing a windows-specific program you may be able to accomplish it this way.
  • QT will also let you do this in a similar manner.
  • GTK is slightly harder.


This video can help you solving your question :)
By: admin