next up previous index
Next: Bitmaps and Pixmaps Up: Basic Tk Previous: Hello World Example

Geometry Manager

Tk has a sophisticated geometry manager, the packer, which   takes care of arranging widgets on the screen and updating the display if new widgets are displayed, their size changes or when they are removed from the display. The pack   command tells the packer how to display a particular widget. The simplest form, e.g.

pack .w
simply displays the widget .w in its parent widget and resizes the parent to leave no free space. The argument -side tells the packer (roughly) which side of the new widget should touch the previously packed one, so for instance
pack .a .b .c -side right
will arrange the widgets .a, .b, .c from right to left. The actual algorithm of the packer is more complex and we will not go into details here.

When widgets have to be arranged in two dimensions, it is necessary to group them first into frame   widgets in one dimension and to pack the frames in the other dimension, e.g. to place four tkmannbuttonsbutton in two rows and columns we would do

frame .a
frame .b
button .a.w1 -text 1
button .a.w2 -text 2
button .b.w1 -text 3
button .b.w2 -text 4
pack .a .b -side top
pack .a.w1 .a.w2 -side left
pack .b.w1 .b.w2 -side left

The first pack command packs the two frames .a and .b in two rows, but until something is packed inside them, they have zero size. The following pack commands insert two buttons horizontally in each frame, which creates two columns in each row:



next up previous index
Next: Bitmaps and Pixmaps Up: Basic Tk Previous: Hello World Example



Micha Meier
Tue Jul 2 09:49:39 MET DST 1996