⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 128.html

📁 Tcl 语言的入门级图书
💻 HTML
字号:
<HTML><TITLE>Widget Characteristics: 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="Sol12.1a">
<STRONG> Solution To Exercise 12.1a</STRONG> </A> <P>



<P>  Making the focus stay at the entry widget is accomplished by
disallowing it at the other places where it can be &#150; namely the
two buttons.  Making the focus start at the entry widget is
accomplished by using the <TT>focus</TT> command in the initializing
script.

<PRE>
proc initForCaps {} {
   global switchState
   .edit_button configure -text Caps \
                -command { set Entry [string toupper $Entry] }
   set switchState initForSmall
}

proc initForSmall {} {
   global switchState
   .edit_button configure -text Small \
                -command { set Entry [string tolower $Entry] }
   set switchState initForCaps
}
proc quit {} {
   global Entry switchState
   destroy .entry .edit_button .quit_button
   unset Entry switchState
   bind . &#60;Key-Tab&#62; {}
}
entry .entry -textvariable Entry
pack .entry
button .edit_button -takefocus 0 -highlightthickness 0
pack .edit_button
button .quit_button -text Quit -command { quit } \
       -takefocus 0 -highlightthickness 0
pack .quit_button
initForCaps
bind . &#60;Key-Tab&#62; { $switchState; break }
focus .entry
</PRE>





<P> <A> <A NAME="Sol12.1b">
<STRONG> Solution To Exercise 12.1b</STRONG> </A> <P>




<PRE>
pack [button .b1 -text Default]
pack [entry .f1]
pack [button .b2 -text {Takes Focus} -takefocus 1]
pack [entry .f2 -takefocus 1]
pack [button  .b3 -text {Does not Take Focus} -takefocus 0]
pack [entry .f3 -takefocus 0]
</PRE>



<P> <A> <A NAME="Sol12.3a">
<STRONG> Solution To Exercise 12.3a</STRONG> </A> <P>



<PRE>
foreach W {3 6} {
   foreach R {raised sunken flat groove ridge} {
       pack  [frame .$R$W -width 4c -height 1c -relief $R -borderwidth $W]
   }
}     
</PRE>




<P> <A> <A NAME="Sol12.3b">
<STRONG> Solution To Exercise 12.3b</STRONG> </A> <P>



The default borderwidth option is 0 which you can verify with

<PRE>
% frame .f
.f
% .f cget -borderwidth
0
</PRE>



<P> <A> <A NAME="Sol12.4a">
<STRONG> Solution To Exercise 12.4a</STRONG> </A> <P>



<PRE>
pack [frame .f -width 1c -height 1c -background #ffffff]
</PRE>




<P> <A> <A NAME="Sol12.4b">
<STRONG> Solution To Exercise 12.4b</STRONG> </A> <P>



<PRE>
foreach C {red yellow blue green magenta violet grey white black hokey} {
   if {[catch {frame .$C -width 2c -height 4m -background $C}]} {
      label .$C -text $C
   } 
   pack .$C
}
</PRE>



<P> <A> <A NAME="Sol12.4c">
<STRONG> Solution To Exercise 12.4c</STRONG> </A> <P>



<P> The solution to this exercise is also available as Script ES12.4c.  It uses
the array method of creating a regional variable, see above in

<A HREF="NotHere.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/NotHere.html">Using Arrays for Missing Features</A>.

<PRE>
proc box {Parent Color {Shape ""}} {
    ## create a new path name
       global box
       if {$Parent=="."} {set Parent ""}
       if {[info exists box(Number)]} { 
          incr box(Number) 
       } else { 
          set box(Number) 1 
       }
       set NewPath $Parent.$Color$box(Number)
    ## determine the height H and width W
       switch $Shape {
          "" { set H 1c; set W 1c }
          h  { set H 1c; set W 3c }
          v  { set H 3c; set W 1c }
          default { return -code error "$Shape is unknown shape for box" }
       }
    ## create the box
       return [frame $NewPath -bg $Color  -width $W -height $H]
    ## report the path name
       return $NewPath
}
</PRE>




<P> <A> <A NAME="Sol12.5a">
<STRONG> Solution To Exercise 12.5a</STRONG> </A> <P>



<PRE>
proc font {Family Weight Slant Size} {
   ## Family: one of 
       set FAMILY {courier helvetica times}
   ## Weight: one of b n  (for bold and normal)
   ## Slant:  one of i n  (for italics/oblique and normal)
   ##         this gets translated differently for different families
   ## Size:   one of 
       set SIZE {8 10 11 12 14 17 24}
   ## returns a font name usable on multiple platforms

   if {[lsearch $FAMILY $Family ]&#60;0} { 
      return -code 1 "1st arg to sdk_font should be one of $FAMILY"
   }
   if {$Weight=="b"} {
      set Weight bold
   } elseif {$Weight=="n"} { 
      set Weight medium
   } else {
      return -code 1 {2nd arg to sdk_font should be "n" or "b"}
   }
   if {$Slant=="i" } {
      if {$Family=="times" } {  set Slant i } { set Slant o }
   } elseif {$Slant=="n"} {
      set Slant r
   } else { 
      return -code 1 {3th arg to sdk_font should be "n" or "i"}
   }
   if {[lsearch $SIZE $Size]&#60;0} { 
      return -code 1 "4th arg to sdk_font should be one of: $SIZE" 
   }
   return "-*-$Family-$Weight-$Slant-normal--$Size-*-*-*-*-*-*-*"
}
</PRE>




<P> <A> <A NAME="Sol12.6a">
<STRONG> Solution To Exercise 12.6a</STRONG> </A> <P>



<PRE>
proc newCursor Widget {
  global newCursor
  incr newCursor(CursorIndex)
  if {$newCursor(CursorIndex) == $newCursor(NumberCursors) } { 
    set newCursor(CursorIndex) 0
  }
  set Cursor [lindex $newCursor(Cursors) $newCursor(CursorIndex)]
  puts $Cursor
  $Widget configure -cursor $Cursor
}

set newCursor(Cursors) { 
    X_cursor target plus tcross crosshair xterm circle man gumby mouse 
    spider spraycan pencil arrow center_ptr 
}
set newCursor(CursorIndex) 0
set newCursor(NumberCursors) [llength $newCursor(Cursors)]

pack [frame .fr -width 3c -height 3c -cursor X_cursor]

bind .fr &#60;Button-1&#62; "newCursor .fr"
</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="12.7.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.7.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="12.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.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 + -