pack()

DESCRIPTION

The pack() method is used to communicate with the packer, a geometry manager that arranges the children of a parent by packing them in order around the edges of the parent.

child.pack(**options)
The command is processed in the same way as pack_configure().

child.pack_configure(**options)
The arguments consist of pairs of arguments that specify how to manage the child. See THE PACKER ALGORITHM below for details on how the options are used by the packer. The following options are supported:
after="other"
Other must the name of another window. Use its parent as the parent for the child, and insert the child just after other in the packing order.
anchor="anchor"
"Anchor" must be a valid anchor position such as "n" or "sw"; it specifies where to position the child in its parcel. Defaults to "center".
before=other
Other must the name of another window. Use its parent as the parent for the child, and insert the child just before other in the packing order.
expand=boolean
Specifies whether the child should be expanded to consume extra space in its paret. Boolean may have any proper boolean value, such as 1 or False. Defaults to 0.
fill="style"
If a child's parcel is larger than its requested dimensions, this option may be used to stretch the child. "Style" must have one of the following values:

"none"
Give the child its requested dimensions plus any internal padding requested with ipadx or ipady. This is the default.
"x"
Stretch the child horizontally to fill the entire width of its parcel (except leave external padding as specified by padx).
"y"
Stretch the child vertically to fill the entire height of its parcel (except leave external padding as specified by pady).
"both"
Stretch the slave both horizontally and vertically.

in_=other
Insert the child at the end of the packing order for the parent window given by other.
ipadx=amount
Amount specifies how much horizontal internal padding to leave on each side of the child. Amount must be a valid screen distance, such as 2 or ".5c". It defaults to 0.
ipady=amount
Amount specifies how much vertical internal padding to leave on each side of the child. Amount defaults to 0.
padx=amount
Amount specifies how much horizontal external padding to leave on each side of the child. Amount may be a list of two values to specify padding for left and right separately. Amount defaults to 0.
pady=amount
Amount specifies how much vertical external padding to leave on each side of the child. Amount may be a list of two values to specify padding for top and bottom separately. Amount defaults to 0
side="side"
Specifies which side of the parent the child will be packed against. Must be "left", "right", "top", or "bottom". Defaults to "top".
If no in, after or before option is specified then the child will be inserted at the end of the packing list for its parent unless it is already managed by the packer (in which case it will be left where it is). If one of these options is specified then the child will be inserted at the specified point. If the child is already managed by the geometry manager then any unspecified options for it retain their previous values rather than receiving default values.

child.pack_forget()
Removes the child from the packing order for its parent and unmaps its window. The child will no longer be managed by the packer.

child.pack_info()
Returns a list whose elements are the current configuration state of the child given by child in the same option-value form that might be specified to pack_configure(). The first two elements of the list are "in: parent" where parent is the child's parent.

parent.pack_slaves()
Returns a list of all of the childs in the packing order for parent. The order of the childs in the list is the same as their order in the packing order. If parent has no childs then an empty string is returned.

THE PACKER ALGORITHM

For each parent the packer maintains an ordered list of childs called the packing list. The in, after, and before configuration options are used to specify the parent for each child and the child's position in the packing list. If none of these options is given for a child then the child is added to the end of the packing list for its parent.

The packer arranges the childs for a parent by scanning the packing list in order. At the time it processes each child, a rectangular area within the parent is still unallocated. This area is called the cavity; for the first child it is the entire area of the parent.
For each child the packer carries out the following steps:
1. The packer allocates a rectangular parcel for the child along the side of the cavity given by the child's side option. If the side is "top" or "bottom" then the width of the parcel is the width of the cavity and its height is the requested height of the child plus the ipady and pady options. For the "left" or "right" side the height of the parcel is the height of the cavity and the width is the requested width of the child plus the ipadx and padx options. The parcel may be enlarged further because of the expand option (see EXPANSION below)
2. The packer chooses the dimensions of the child. The width will normally be the child's requested width plus twice its ipadx option and the height will normally be the child's requested height plus twice its ipady option. However, if the fill option is "x" or "both" then the width of the child is expanded to fill the width of the parcel, minus twice the padx option. If the fill option is "y" or "both" then the height of the slave is expanded to fill the width of the parcel, minus twice the pady option.
3. The packer positions the child over its parcel. If the child is smaller than the parcel then the anchor option determines where in the parcel the child will be placed. If padx or pady is non-zero, then the given amount of external padding will always be left between the child and the edges of the parcel.

Once a given child has been packed, the area of its parcel is subtracted from the cavity, leaving a smaller rectangular cavity for the next child. If a child does not use all of its parcel, the unused space in the parcel will not be used by subsequent childs. If the cavity should become too small to meet the needs of a child then the child will be given whatever space is left in the cavity. If the cavity shrinks to zero size, then all remaining childs on the packing list will be unmapped from the screen until the parent window becomes large enough to hold them again.

EXPANSION

If a master window is so large that there will be extra space left over after all of its childs have been packed, then the extra space is distributed uniformly among all of the childs for which the expand option is set. Extra horizontal space is distributed among the expandable childs whose side is "left" or "right", and extra vertical space is distributed among the expandable childs whose side is "top" or "bottom".

GEOMETRY PROPAGATION

The packer normally computes how large a parent must be to just exactly meet the needs of its childs, and it sets the requested width and height of the parent to these dimensions. This causes geometry information to propagate up through a window hierarchy to a top-level window so that the entire sub-tree sizes itself to fit the needs of the leaf windows. However, the pack_propagate() method may be used to turn off propagation for one or more parents. If propagation is disabled then the packer will not set the requested width and height of the packer. This may be useful if, for example, you wish for a parent window to have a fixed size that you specify.