Newbie problem with Tkinter
Fredrik Lundh
fredrik at effbot.org
Sun Nov 5 17:48:03 EST 2000
Rick Morneau wrote:
> I'm trying to use the <Configure> event in Tkinter, but it always
> returns the exact same width and height regardless of the actual
> size of the frame.
not always -- did you try making the window *smaller*? ;-)
> Here is a simple example:
>
> #! /usr/local/bin/python
>
> from Tkinter import *
>
> root = Tk()
>
> def callback(event):
> print "New width and height:", event.width, event.height
>
> frame = Frame(root, width=100, height=100)
try this:
frame = Frame(root, width=100, height=100, bg="blue")
> frame.bind("<Configure>", callback)
> frame.pack()
>
> root.mainloop()
the problem here is that "pack" without options just displays
the widget; it doesn't "attach" it to the parent. if the parent
is made larger, the widget is just centered along the top edge.
to fix this, change the pack() call to:
frame.pack(fill=BOTH, expand=1)
which basically means that the widget should expand into
unused space both vertically and horizontally.
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list