Horizontal and Vertical Stacking

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.

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.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.237.77