Tkinter pack bug in Python 2.3

F

Frank Stajano

The compact form of pack behaves differently (and I believe incorrectly)
compared to the long form. The following two scripts demonstrate it, at
least on this interpreter:
Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
[GCC 3.3.1 (cygming special)] on cygwin


# First script, no bug

# I want a canvas inside a frame inside a toplevel, with the canvas
# filling the toplevel even as I resize the window. This does it.

from Tkinter import *

root = Tk()
frame = Frame(root, bg="lightBlue")
frame.pack(side=TOP, expand=1, fill=BOTH)
canvas = Canvas(frame, bg="lightGreen")
canvas.pack(side=TOP, expand=1, fill=BOTH)

mainloop()





# 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)
canvas = Canvas(frame, bg="lightGreen").pack(side=TOP, expand=1, fill=BOTH)

mainloop()



Frank (filologo disneyano) http://www-lce.eng.cam.ac.uk/~fms27/
 
P

Peter Otten

Frank said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top