[Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective?

Michael Lange klappnase at web.de
Fri Dec 17 21:53:08 CET 2010


Hi,

Thus spoketh "Michael O'Donnell" <michael.odonnell at uam.es>
unto us on Fri, 17 Dec 2010 19:14:27 +0100:

(...)
>
> The Label widget in fact REPLACES the canvas in the display
> rather than being packed within it. I don't know why (try commenting out
> the d.pack() line) and see the difference.)
>

I changed your example a bit, and so we can see that actually the canvas
is resized:

from Tkinter import *
root = Tk()
root.geometry('500x500')
c=Canvas(root, bg="red", width=400, height=400, relief='solid', bd=4)
c.pack()
d=Label(c, text="Hello", relief='sunken', bd=2)
d.pack()
c.update_idletasks()
print c.winfo_height(), c.winfo_width()
root.mainloop()

You can avoid this by ading a c.pack_propagate(0) before packing the
label. However I agree, it's better to use create_window() to avoid
pitfalls like this.

Regards

Michael



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

To live is always desirable.
		-- Eleen the Capellan, "Friday's Child", stardate 3498.9


More information about the Tkinter-discuss mailing list