[ Next: VarCouplings | Previous: SettingOptions | Contents ]

The Packer

The packer is one of tk's geometry-management mechanisms. See the Packer class interface doc.

Geometry managers are used to specify the relative positioning of the positioning of widgets within their container - their mutual master. In contrast to the more cumbersome placer (which is used less commonly, and we do not cover here), the packer takes qualitative relationship specification - above, to the left of, filling, etc - and works everything out to determine the exact placement coordinates for you.

The size of any master widget is determined by the size of the "slave widgets" inside. The packer is used to control where slave widgets appear inside the master into which they are packed. You can pack widgets into frames, and frames into other frames, in order to achieve the kind of layout you desire. Additionally, the arrangement is dynamically adjusted to accomodate incremental changes to the configuration, once it is packed.

Note that widgets do not appear until they have had their geometry specified with a geometry manager. It's a common early mistake to leave out the geometry specification, and then be surprised when the widget is created but nothing appears. A widget will appear only after it has had, for example, the packer's pack() method applied to it.

The pack() method can be called with keyword-option/value pairs that control where the widget is to appear within its container, and how it is to behave when the main application window is resized. Here are some examples:

fred.pack() #defaults to side = "top" fred.pack(side = "left") fred.pack(expand = 1)

Packer Options

For more extensive information on the packer and the options that it can take, see the man pages and page 183 of John Ousterhout's book.

anchor
Anchor type. Denotes where the packer is to place each slave in its parcel.
expand
Boolean, 0 or 1
fill
Legal values: "x", "y", "both", "none".
ipadx and ipady
A distance - designating internal padding on each side of the slave widget.
padx and pady
A distance - designating external padding on each side of the slave widget.
side
Legal values are : "left", "right", "top", "bottom". Contained widgets (slaves) are packed close up against the specified side of the widget being packed (the master).