Geometry Management
You’ve already seen the
purpose of the pack
method. The name of the game
is “geometry management,” the art of arranging widgets on
the screen and specifying a policy for rearranging themselves when
the screen is resized. Tk supports three types of geometry managers:
placer, packer, and grid. The placer is the simplest of the lot. Like
Motif’s Bulletin Board widget or Visual Basic’s geometry
management policy, you have to specify the x and
y coordinates of each widget. I’ll just
refer you to the Tk documentation for more details on the placer.
Packer
The packer, like Motif’s Form
widget, is a powerful constraint-based geometry manager. The packer
is not an object; it is simply the algorithm implemented by the
pack()
method. In other words, the call
$widget—>pack()
is a request to the
widget to pack itself in the next available space inside its
containing widget.
When you pack a suitcase, you typically start at one end and, for every item, proceed to fill in the remaining space. The packer works exactly like this, but there’s one crucial difference. Once it sticks a widget onto an edge of a container widget, it slices off that entire edge and takes it off the remaining available space. Figure 14.10 illustrates the packing algorithm.
Figure 14-10. Packing algorithm
In this figure, if the side
were specified as
top
or bottom
, the
height of the label would dictate the ...
Get Advanced Perl Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.