Pack is the oldest general purpose geometry managers in Tk.
Figure 4.1. Filtered Pack Properties
»Pack« operates on a spatial geometry model. Any window managed by »pack« is oriented toward a side or corner of its container window – mostly the parent window. This allows for surprisingly simple configuration code, but it’s also a stark limitation layout-vise! See Figure 4.2, “Pack is Spatial Oriented”
Figure 4.2. Pack is Spatial Oriented
The three frames in Figure 4.2, “Pack is Spatial Oriented” are packed in the following order: »black« -side left -fill y, »gray« -side top -fill x and »red« -side bottom. Expand is set to »1« for red. At most, three windows can be layouted inside a single region through »pack«.
-side left -fill y
-side top -fill x
-side bottom
Menu Bar: Option Menu
Figure 4.3. Options Menu
Jeszra distinguishes between the container window and the parent window. The default setting ensures that only the parent window is being used as the container. This is controlled by the Options Menu inside of Jeszra’s menu bar.
Figure 4.4. Black Re-packed
Re-packing »black« –with the same geometry options– produces the design of Figure 4.4, “Black Re-packed”. Pack is a non-commutative geometry manager. The layout is a function from when the window was put under pack’s supervision and its configuration.
Suppose: You wanted your own version of Rtl_gridwin with pack as the favorite geometry manager.
The black, gray and red example is almost there; only on the wrong sides; and black and gray should not touch. Within Jeszra drag gray and then the red window onto the parent window. Now the layout resembles Figure 4.2, “Pack is Spatial Oriented”. It is still needed to tell black to vacant the height of gray on top. This is done through the geometry property »pady«. Setting pady to »20 0« will tell black to yield 20 pixels on top and none at the bottom.
…Hierarchy Options
Insert To»Insert To«, instructs Jeszra to use the current selected window as the container and parent for the next inserted window. Jeszra treats »frame«s, »toplevel«s, »menubutton« and »menu«s as containers. Of course, every window with a built-in geometry manager, such as »canvas« or »zinc« are also used as containers. Using »Insert To« forces Jeszra to use any current selected window as a container. …In Any Window, …Only By ParentDefault: The parent is always the container window. This checkbutton allows to separate containers from parent window. If »Any Window« is activated, while a window is being dragged from a pack container into a sibling window, then the sibling window becomes the container of the dragged window. Flat Hierarchy On, Deep Hierarchy OnDefault: Deep Hierarchy. In a flat window hierarchy, any inserted window is a direct child of the toplevel window. As a result the container is hardly ever the parent window. »In Any Window« is automatically disabled, whenever flat hierarchy is turned on –The container must differ from the parent window.
»Insert To«, instructs Jeszra to use the current selected window as the container and parent for the next inserted window. Jeszra treats »frame«s, »toplevel«s, »menubutton« and »menu«s as containers. Of course, every window with a built-in geometry manager, such as »canvas« or »zinc« are also used as containers. Using »Insert To« forces Jeszra to use any current selected window as a container.
Default: The parent is always the container window. This checkbutton allows to separate containers from parent window. If »Any Window« is activated, while a window is being dragged from a pack container into a sibling window, then the sibling window becomes the container of the dragged window.
Default: Deep Hierarchy. In a flat window hierarchy, any inserted window is a direct child of the toplevel window. As a result the container is hardly ever the parent window. »In Any Window« is automatically disabled, whenever flat hierarchy is turned on –The container must differ from the parent window.
Figure 4.5. Gray padX set to »0 20«
»pady« and »padx« are read-only inside the Inspector. You have to make them writable again in order to perform these steps.
Preferences: Global Filters
Open »Preferences« from the »Edit« Menu and go to the »Filters« page. Select »Category:« Geometry.
The read-only section is hidden at the bottom of the Filters page. Make this section visible and remove »pad(x|y)« from the left Gistbox labeled: »...everywhere:«.
Refresh the geometry page inside the Inspector, by a single click on the »Geometry« tab. Now »pady« and »padx« are writable.
Alternatively use »Disable Global Filters«, from the Inspector context menu, to temporarily deactivate global filters.
Figure 4.6. Read-only Properties
Figure 4.7. Unfiltered Pack Properties
Flaws with Pack-Rtl_gridwin
Assuming black and gray represent scrollbars. Solution: change the packing sides for all windows; black to »right«, gray to »bottom« and red to »top«.
Coding would be required to set pady: For each resize event on gray; even before managing its geometry.
Example 4.6. Query Size before Management
scrollbar .gray -orient horizontal scrollbar .black some-window .red # make the geometry management. pack .black \ -side right -fill y \ -pady [list [winfo reqheight .gray] 0] pack .gray -side bottom -fill x pack .red -side top -fill both -expand 1 bind .gray < Configure > { pack configure .black \ -pady [list [winfo height .gray] 0] }
Although, the Example 4.6, “Query Size before Management” would do the job, it’s awkward!
Figure 4.8. Relevant Gray Pack Properties
The geometry manager pack is suitable for ragged designs, without interactive layout changes. It could be used for »OK«, »Cancel«, »Abort«, »Retry« , »Yes« and »No« button bars, at the bottom of a dialog. However, when the resulting dialog is to be deployed under different windowing systems: Pack is ill fitted for the job.
Figure 4.9. Relevant Red Pack Properties
Much more complex designs are still possible with pack, but this requires a more complex window structure. That is: Additional containers have to be introduced, just for geometry management. As a rule of thumb: deeper window hierarchies are less flexible than flat ones.
Flat hierarchies are very relevant for striped interfaces, since each partly visible container must be striped, too. Hence, the graphical workload correlates with the window structure.
Copyright © 2009–2010 Arndt Roger Schneider