Tkinter pack bug in Python 2.3

Peter Otten __peter__ at web.de
Sun Nov 2 08:23:00 EST 2003


Frank Stajano wrote:

> 
> The compact form of pack behaves differently (and I believe incorrectly)
> compared to the long form. The following two scripts demonstrate it, at

There is no "compact form", see below.

[...]

> # Second script, bug
> 
> # I want a canvas inside a frame inside a toplevel, with the canvas
> # filling the toplevel even as I resize the window. This doesn't do
> # it, and instead makes the canvas a sibling of the frame, instead of
> # a child. (Try resizing the toplevel and you'll see.) Why?
> 
> from Tkinter import *
> 
> root = Tk()
> frame = Frame(root, bg="lightBlue").pack(side=TOP, expand=1, fill=BOTH)

You are assigning the result of the pack() method, i. e. None, to frame
here, and consequently Canvas is constructed with None instead of a Frame
instance as the first argument.

> canvas = Canvas(frame, bg="lightGreen").pack(side=TOP, expand=1,
> fill=BOTH)
> 
> mainloop()

Peter




More information about the Python-list mailing list