Tkinter Grid manager question

jepler at unpythonic.net jepler at unpythonic.net
Tue Jul 23 22:56:19 EDT 2002


By default, a frame ignores the width= and height= it is given, and instead
calculates the amount of space needed by the widgets it manages via grid or
pack.

You can tell the grid manager that it should not behave in this way, and
should instead take the width= and height= you select for the frame and
parcel that space out to the managed widgets:
    f1.grid_propagate(0)
now, f1 will be 900x100

Similarly, if you "grid" things into f1_1 you need to run
    f1_1.grid_propagate(0)
if you "pack" things into f1_1, you need to run
    f1_1.pack_propagate(0)

If you want to make sure the rows are the same width, you need to set
the weight (again on the master):
    for row in range(4):
	f1.grid_rowconfigure(row, weight=1)
now, f1_1, f1_2, f1_3, and f1_4 will be configured to get equal shares of
the height of f1.

If you still don't get a layout exactly 225 pixels wide, this is probably
because of the borderwidth.  For instance, if you configure a frame width a
thick border and then make another frame inside, the inner frame is
smaller (shifting to tcl since that's easier to do):
    %frame .f -bd 25 -relief raised -width 100 -height 100
    frame .f.f
    pack prop .f 0
    pack .f
    pack .f.f -expand 1 -fill both
    wm geo .
    winfo geo .f
    winfo geo .f.f
. and .f have geometries of 100x100, while .f.f is only 50x50, due to the
border of .f.

Geometry management in Tk is a somewhat complex issue, and you have to
expect to play with the options before you get what you want.

Usually you will want to have as few intervening levels of frames as
possible.

Jeff




More information about the Python-list mailing list