When a widget is created, it is not yet visible on the window. Only by packing on a window or some other widget will a widget become visible. We've seen simple examples of packing before in sections 3.3 and 3.9. The packer is used to tell Tk where to place a widget, relative to other widgets. Suppose we want one button on the right side of a window and two buttons at the right side, as in figure 1:
% button .b1 -text "Button 1" .b1 % button .b2 -text "Button 2" .b2 % button .b3 -text "Button 3" .b3 % pack .b1 -side left -fill both % pack .b2 -side top % pack .b3 -side bottom
Figure 1: Example of using the Tk packer, using filling
Figure 2: Example of using the Tk packer, without filling
The -side
argument is used to indicate on which side of the remaining
space the widget is to be placed, the new remaining space will be the other
side. The -fill
argument is used to let a widget take all available
space (compare figure 1 to figure
2).
The exact workings of the Tk packer are a bit obscure and are explained in detail in [2].