Previous: Command binding
Up: Widgets
Next: Using frames to improve packing
Previous Page: Command binding
Next Page: Using frames to improve packing

Packing

TCL provides a means of packing widgets together, and laying them out on the screen. This enables widgets to be placed on the screen in a flexible,and useful way. The operation of the packer is slightly complicated, and it is perhaps best to use it only for horizontal or vertical packing.

For example

button .button1 -text "Button1" -command "cmd1" 
     button .button2 -text "Button2" -command "cmd2" 
     button .button3 -text "Button3" -command "cmd3" 
     pack .button1 .button2 .button3

simply creates three buttons, and packs them vertically, while.

button .button1 -text "Button1" -command "cmd1" 
     button .button2 -text "Button2" -command "cmd2" 
     button .button3 -text "Button3" -command "cmd3" 
     pack .button1 .button2 .button3 -side left

packs the three buttons in a horizontal line. Conceptually the pack operation starts with an empty rectangular space, and then takes each widget from the list of widgets to pack, and places it at an appropriate position. This can be at the top, bottom, left or right. Effectively a ractangular space which extends either across the initial space (for top and bottom options), or down the space (for left and right options) is allocated to the packed widget. The remaining space is available for packing other widgets, which are handled in exactly the same way, until no more widgets need to be packed. The default location for packing is at the top, which gives the vertical display shown in the first example. Although two dimensional packing is possible by this algorithm, arbitrary two dimensional layout is not, without the use of some container widgets, such as frames or toplevels. Frequently frames will be created in which to pack other widgets either horizontally or vertically, since this usually simplifies packing considerably.



Previous: Command binding
Up: Widgets
Next: Using frames to improve packing
Previous Page: Command binding
Next Page: Using frames to improve packing

csstddm@brunel.ac.uk
Fri Aug 19 16:55:19 BST 1994