Managing the window size (and layout) in Tcl/Tk
Archive - Originally posted on "The Horse's Mouth" - 2015-03-12 00:15:17 - Graham Ellis
The buttons on the left are in a frame of their own, and the graphic area ("Canvas") across on the right is in a separate frame - the frames being named .left and .right, and the widgets within them things like .left.mkm and .left.quit and .right.graph, so that the geomentry manager knows where they fit in the heirarcy.
One of the requirements of this appliaction is that we limit resizing so that the GUI window cannot be shrunk below its initial size, and we've done that using the following code:
set size [wm geometry .]
regexp {(\d+)x(\d+)} $size all w h
wm minsize . $w $h
Which is reading the size that the window is initially set to, and then saying that the window manager should not reduce below that. One thing you need to be sure of before you ask for the size of the window is that it has actually been renedered on the screen, and as Tk only draws when its event loop is empty, or on specific request, you will probably need to add:
update idletasks
in your code just before asking for the geometry size.
Complete source code at [here]. Other examples of nested frames at [here] and [here].