Horizontal and Vertical Stacking

   

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 23.  The Pack Geometry Manager


In general, you use either horizontal or vertical stacking within a frame. If you mix sides such as left and top, the effect might not be what you expect. Instead, you should introduce more frames to pack a set of widgets into a stack of a different orientation. For example, suppose we want to put a row of buttons inside the upper frame in the examples we have given so far:

Example 23-3 A horizontal stack inside a vertical stack.

graphics/23fig03.gif

 frame .one -bg white frame .two -width 100 -height 50 -bg grey50 # Create a row of buttons foreach b {alpha beta gamma} {    button .one.$b -text $b    pack .one.$b -side left } pack .one .two -side top 
Example 23-4 Even more nesting of horizontal and vertical stacks.

graphics/23fig04.gif

 frame .one -bg white frame .two -width 100 -height 50 -bg grey50 foreach b {alpha beta} {    button .one.$b -text $b    pack .one.$b -side left } # Create a frame for two more buttons frame .one.right foreach b {delta epsilon} {    button .one.right.$b -text $b    pack .one.right.$b -side bottom } pack .one.right -side right pack .one .two -side top 

You can build more complex arrangements by introducing nested frames and switching between horizontal and vertical stacking as you go. Within each frame pack all the children with either a combination of -side left and -side right, or -side top and -side bottom.

Example 23-4 replaces the .one.gamma button with a vertical stack of two buttons, .one.right.delta and .one.right.epsilon. These are packed toward the bottom of .one.right, so the first one packed is on the bottom.

The frame .one.right was packed to the right, and in the previous example, the button .one.gamma was packed to the left. Despite the difference, they ended up in the same position relative to the other two widgets packed inside the .one frame. The next section explains why.


       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net