Tkinter Toplevel geometry
Russell E. Owen
rowen at cesmail.net
Mon Mar 26 21:04:15 CEST 2007
In article <1174803181.656189.303200 at l77g2000hsb.googlegroups.com>,
"Chris" <ceball at gmail.com> wrote:
> If a user resizes a Toplevel window, or I set a Toplevel's geometry
> using the geometry() method*, is there any way to have the geometry
> reset to that required for all the widgets?
> I think I found what I'm looking for in tk itself:
> 13.3. How can I clear the geometry settings for a toplevel?
> If you want to have Tk resize your toplevel to what the toplevel
> requires (ie: the user might have resized it, or a widget was
> removed), use [wm geometry $toplevel].
I'm glad you got that figured out.
Here's a variant question that has driven me crazy...how to create a
general-purpose variation of toplevel that:
- can only be resized in one direction and auto-sizes (to fit widgets)
in the other direction?
- has a "reasonable" initial size in the resizable direction.
The first part is easy -- just use the "resizable" method. I've never
figured out a clean solution to the second question because:
- tk doesn't allow setting just X or Y size of a toplevel (the geometry
call requires both or neither)
- one can use a frame to force the resizable dimension to the desired
initial value, but to do that you either have to know in advance what
geometry manager the user is using, or make them pack their widgets into
a frame inside the toplevel
I ended up binding to the Configure event, but it's rather messy for
such a simple-seeming thing. (The really aggravating part is that perl
can do this directly because it uses C instead of tcl to talk to tk, and
tk's C interface is more flexible about setting toplevel geometry!).
More information about the Python-list