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

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


The answer to your specific question is no. You can't have two states or otherwise use pack two different ways in the same parent.

However, what I think you want to accomplish is simple. Use the built-in features of the canvas to create an image item that is part of the canvas, then pack things into the canvas as if it were a frame.

You can accomplish a similar thing by creating a label widget with an image, then pack your other widgets into the label.

One advantage to using a canvas is you can easily tile an image to fill the whole canvas with a repeating background image so as the window grows the image will continue to fill the window (of course you can just use a sufficiently large original image...)


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.


... 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.