📄 139.html
字号:
<HTML><TITLE>Geometry Management: Solutions to Exercises</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Solutions to Exercises</H1></A>
<P> <A> <A NAME="Sol13.1a">
<STRONG> Solution To Exercise 13.1a</STRONG> </A> <P>
<PRE>
proc forgetGeometry Master {
foreach S [pack slaves $Master] { forgetGeometry $S }
pack forget $Master
foreach S [grid slaves $Master] { forgetGeometry $S }
grid forget $Master
}
</PRE>
<P> <A> <A NAME="Sol13.2a">
<STRONG> Solution To Exercise 13.2a</STRONG> </A> <P>
<PRE>
## 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
</PRE>
<P> <A> <A NAME="Sol13.2b">
<STRONG> Solution To Exercise 13.2b</STRONG> </A> <P>
<PRE>
## 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
</PRE>
<P> <A> <A NAME="Sol13.3a">
<STRONG> Solution To Exercise 13.3a</STRONG> </A> <P>
<P> Here is one possibility.
<P>
<PRE>
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
</PRE>
<P> <A> <A NAME="Sol13.3b">
<STRONG> Solution To Exercise 13.3b</STRONG> </A> <P>
<PRE>
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
</PRE>
<P> <A> <A NAME="Sol13.3c">
<STRONG> Solution To Exercise 13.3c</STRONG> </A> <P>
<PRE>
pack [box . red] -expand true
</PRE>
<P> <A> <A NAME="Sol13.3d">
<STRONG> Solution To Exercise 13.3d</STRONG> </A> <P>
<PRE>
## 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
</PRE>
<P> <A> <A NAME="Sol13.5a">
<STRONG> Solution To Exercise 13.5a</STRONG> </A> <P>
<PRE>
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
</PRE>
<P> <A> <A NAME="Sol13.6a">
<STRONG> Solution To Exercise 13.6a</STRONG> </A> <P>
<P> Here is a completely commented rendition of the script.
<PRE>
# *********************************************************************
# 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
</PRE>
From this rendition you see that
<OL>
<P> <P><LI> The grey box on the left is centered in the second slice which extends
up as far as the four squares up to the first slice.
<P> <P><LI> The upper row of two squares is the fifth slicing and has an
attached cavity on the left.
<P> <P><LI> The lower row of two squares is the fourth slicing and has
an attached cavity between the two squares.
<P> <P><LI> There are no other attached cavities.
<P> <P><LI> As the window expands horizontally:
<UL>
<P> <P><LI> No box will change size because there is no <TT>-fill</TT> option applied
to a box.
<P> <P><LI> The top grey box will remain centered horizontally in its slice
that will continue to stretch across the top.
<P> <P><LI> the two attached cavities will become visible. They will look like background space.
</UL>
<P> <P><LI> As the window expands vertically:
<UL>
<P> <P><LI> No box will change size becaue there is no <TT>-fill</TT> option applied
to a box.
<P> <P><LI> The left grey box will remain centered vertically in its slice that
lies on the left under the top slice.
<P> <P><LI> The other five boxes appear in two horizontal and two vertical slices.
<P> <P><LI> The boxes in horizontal slices will appear within extra vertical space
because a <TT>-fill both</TT> option was used in the creation of these slices.
<P> <P><LI> The boxes in the vertical slices will appear within extra vertical space
because vertical slices expand vertically by default.
</UL>
</OL>
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.9a: Expansion of Figure 13.6a</ADDR></CAPTION>
</TABLE></CENTER><P>
<P> <A> <A NAME="Sol13.6b">
<STRONG> Solution To Exercise 13.6b</STRONG> </A> <P>
<PRE>
## 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]
</PRE>
<P> <A> <A NAME="Sol13.7a">
<STRONG> Solution To Exercise 13.7a</STRONG> </A> <P>
<P> You can do this directly with frames or you can use the <TT>box</TT> 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, <TT>[. cget -bg]</TT>. 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
<TT>cget</TT> 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.
<P> Here is a solution that uses <TT>box</TT> througout.
<PRE>
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
</PRE>
<P> <A> <A NAME="Sol13.7b">
<STRONG> Solution To Exercise 13.7b</STRONG> </A> <P>
<PRE>
grid [box . white v] [box . grey50] -sticky ne
grid x [box . black h]
</PRE>
<P> <A> <A NAME="Sol13.8a">
<STRONG> Solution To Exercise 13.8a</STRONG> </A> <P>
<PRE>
## 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
</PRE>
<P> <A> <A NAME="Sol13.8b">
<STRONG> Solution To Exercise 13.8b</STRONG> </A> <P>
<PRE>
pack [frame .f -width 375 -height 300]
pack propagate .f false
pack [text .f.t]
</PRE>
<!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="13.8.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.8.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="13.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
</NOBR></FONT></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -