| 13.9 Solutions to Exercises |
|
|
proc forgetGeometry Master {
foreach S [pack slaves $Master] { forgetGeometry $S }
pack forget $Master
foreach S [grid slaves $Master] { forgetGeometry $S }
grid forget $Master
}
## left slice pack [box . white v] -side left ## middle slice pack [frame .middle] -side left pack [box .middle red] [box .middle blue] [box .middle yellow] ## right slice pack [box . white v] -side left
## left slice pack [box . white v] -side left ## middle slice pack [frame .middle] -side left pack [box .middle red] [frame .middle.center] [box .middle yellow] ## slice center frame of middle slice vertically set MiddleBlue [box .middle.center blue] set Width [expr [$MiddleBlue cget -width]/2] $MiddleBlue configure -width $Width set MiddleBlack [box .middle.center black] $MiddleBlack configure -width $Width pack $MiddleBlack $MiddleBlue -side left ## right slice pack [box . white v] -side left
Here is one possibility.
pack [frame .f1] -side left -expand true -fill both pack [box .f1 red] pack [box .f1 green] -fill both pack [frame .f2] -side left -expand true -fill both pack [box .f2 blue] -expand true pack [box .f2 yellow] -expand true -fill both
pack [box . red] -side left pack [frame .pad1] -side left -fill both -expand true pack [box . blue] -side left pack [frame .pad2] -side left -fill both -expand true pack [box . black] -side left
pack [box . red] -expand true
## top slice
pack [frame .top] -expand true -fill both
pack [frame .top.white -bg white -width 3c -height 3c] \
-side left -expand true -fill both
pack [frame .top.slider -bg grey50 -width 5m] \
-side left -fill both
## bottom slice
pack [frame .bottom] -fill both
pack [frame .bottom.slider -bg grey50 -height 5m] \
-side left -expand true -fill both
pack [frame .bottom.pad -bg black -width 5m -height 5m] -side left
for {set I 0} {$I<=3} {incr I} {
for {set J 0} {$J<=2} {incr J} {
set Grid($I,$J) [box . black]
grid $Grid($I,$J) -row $I -column $J -padx 2m -pady 2m
}
}
destroy $Grid(2,1)
grid $Grid(1,1) -rowspan 2 -sticky news
Here is a completely commented rendition of the script.
# *********************************************************************
# the first slicing is horizontal, complete and has just one slice
# that lies across the entire top of the window
# ************
pack [box . grey50] -expand true
# *********************************************************************
# the second slicing is vertical, complete, and has just one slice
# that lies on the left under the top slice
# ************
pack [box . grey50] -side left
# *********************************************************************
# the third slicing is horizontal, complete, and has one slice
# that lies just under first slice and to the left of the second
# ************
pack [frame .fr] -side bottom -expand true -fill both
# *********************************************************************
# the fourth slicing is vertical, incomplete, and has two slices
# that lie just under the third slicing -- the attached cavity
# lies between the two slices
# ************
pack [box . black] -side left
pack [box . white] -side right
# *********************************************************************
# the fifth slicing is a vertical slicing of the third slice; it is
# incomplete, and has two slices; its cavity lies to the far left
# ************
pack [box .fr black] -side right
pack [box .fr white] -side right
From this rendition you see that
## first vertical slice goes on left
pack [frame .left] -side left -expand true -fill both
## slice the first slice horizontally
pack [frame .left.white -bg white -width 3c -height 3c] \
-expand true -fill both
pack [frame .left.slider -bg grey50 -height 5m] -fill both
## complete vertical slicing by horizontally slicing its attached cavity
pack [frame .slider -bg grey50 -height 5m] \
-expand true -fill both
pack [frame .pad -bg black -width 5m -height 5m]
You can do this directly with frames or you can use the box procedure. If the latter, the need for a box to provide padding in the lower left can be a problem. What color should this box be? The same as the default background color, that is, [. cget -bg]. One way to get the default background color is, of course, to make the padding with a frame rather than a box. What dimensions should that frame have? The same dimensions as the adjoining boxes. Do not assume you know these dimensions. Get them with the cget action. If you do assume you know these dimensions, the code you write will break when somebody decides that the boxes should be a different size. Here is a solution that uses box througout.
pack [frame .top] \
-expand true -fill both
pack [box .top white v] \
-side left
pack [box .top grey50] \
-anchor ne -side left -expand true
pack [box . [. cget -bg]] \
[box . black h] \
-side left
grid [box . white v] [box . grey50] -sticky ne grid x [box . black h]
## first horizontal slice has white boxes at either end pack [frame .top] -fill both pack [box .top white] -side left pack [box .top white] -side right ## third horizontal slice has white boxes at either end pack [frame .bottom] -fill both -side bottom pack [box .bottom white] -side left pack [box .bottom white] -side right ## second horizontal slice is just an expanding space pack [frame .space] -fill both -expand true
pack [frame .f -width 375 -height 300] pack propagate .f false pack [text .f.t] |
Author's Home Page |
|
Order from Amazon. |