By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

Tkinter pack bug in Python 2.3

P: n/a

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/
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a

"Frank Stajano" <fm***@cam.ac.uk

Old Perl programmer, hmm... ;-)

Kindly
MichaelP
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.