Tkinter Toplevel geometry

James Stroud jstroud at mbi.ucla.edu
Sun Mar 25 07:40:44 EDT 2007


Chris wrote:
> Hi,
> 
> 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].
> """
> [from http://tcl.sourceforge.net/faqs/tk/]
> 
> 
> 
> * for instance, if I want to turn of Tkinter's automatic adjustment of
> the window to fit all the widgets by doing something like
> self.geometry(self.geometry()), is there any way to undo that?
> 
> Thanks,
> Chris
> 

Hi Chris,

I think you are on to something. The equivalent of

    [wm geometry $toplevel]

in Tkinter would be

    sometop.geometry()

Or, equivalently,

    sometop.wm_geometry()

Or, calling the underlying tcl/tk interpreter directly

    sometop.tk.call('wm', 'geometry', str(sometop))

Which is redundant, but emphasizes the point: This does not resize the
widget as expected nor does it cause the window to resize upon adding 
new packing slaves--at least for the X11 based Tkinter for mac via the 
fink debian based package manager.

Really wish things worked according to the docs a lot of the time or 
that they weren't so poorly written. Perhaps they are implying that you 
must pass parameters, however they do not explain how one might generate 
said parameters to get the required size to which they allude. Terribly 
disappointing.

James



More information about the Python-list mailing list