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

Michael O'Donnell michael.odonnell at uam.es
Fri Dec 17 19:14:27 CET 2010

Hi Malcom,

I have never heard of packing widgets within a canvas. Just use create_window,
so there is no automatic placement, you need to handle all placement.

Note with the following, packing a label within a canvas:

from Tkinter import *
root = Tk()
c=Canvas(root, bg="red", width=400, height=400)
d=Label(c, text="Hello")

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


On Fri, Dec 17, 2010 at 6:52 PM,  <python at bdurham.com> wrote:
> This question is related to using Canvases and Frames as containers and does
> not consider the drawing capabilities of the Canvas widget.
> Canvas and Frames are both containers. My understanding is that both of
> these containers provide identical layout behaviors via their pack, grid,
> and place methods (is this really true?). In other words, I should be able
> to replace a Frame with a Canvas and have identical behavior, correct?
> From a container perspective, would it be correct to describe a Canvas as an
> enhanced Frame with the following capabilities?
> - the ability to support virtual sizes greater than the visible display area
> - the scrollbar, scroll and viewport features associated with having a
> larger virtual display area
> One of my points of confusion with Canvas containers is figuring out what
> techniques to use for the layout of traditional widgets. Can I use regular
> pack and grid placement always, only when a canvas does not have scrolling,
> or never? When should one use the create_window() technique for widget
> placement?
> Thank you,
> Malcolm
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

More information about the Tkinter-discuss mailing list