📄 117.html
字号:
<HTML><TITLE>Overview of Tk: 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="Sol11.1a">
<STRONG> Solution To Exercise 11.1a</STRONG> </A> <P>
There is no answer to give for this question.
<P> <A> <A NAME="Sol11.3a">
<STRONG> Solution To Exercise 11.3a</STRONG> </A> <P>
<P> Both command and variable substitution would happen during initialization.
The event handler for <TT>.edit_button</TT> would simply reset <TT>Entry</TT> to the
empty string each time it is executed.
<P> <A> <A NAME="Sol11.3b">
<STRONG> Solution To Exercise 11.3b</STRONG> </A> <P>
In Script S11.1a, the variable named <TT>Entry</TT> is not evaluated in the
command that creates <TT>.edit_button</TT>. The script that is declared with the
<TT>-commmand</TT> option will be executed in the top-level namespace, if and when
it is executed. This means that <TT>Entry</TT> refers to a top-level variable
without being declared with <TT>global</TT>.
<P> <A> <A NAME="Sol11.3c">
<STRONG> Solution To Exercise 11.3c</STRONG> </A> <P>
<PRE>
pack [entry .entry -textvariable Entry]
pack \
[button .edit_button -text Caps -command {set Entry [string toupper $Entry]} ]
pack [button .quit_button -text Quit -command exit]
</PRE>
<P> <A> <A NAME="Sol11.4a">
<STRONG> Solution To Exercise 11.4a</STRONG> </A> <P>
<P> The phrase "That tickles!" is repeatedly written in the command window as
the mouse moves over any part of the root window except the <TT>.quit_button</TT>
widget. The reason is that although both bindings apply to the
<TT>.quit_button</TT> widget, the binding whose event handler is simply <TT>break</TT>
fires first. This causes any other applicable bindings to be skipped.
<P> By the way, since most Tk applications are run directly when in production
use, writing to the command window this way is useless except for training and
debugging.
<P> <A> <A NAME="Sol11.4b">
<STRONG> Solution To Exercise 11.4b</STRONG> </A> <P>
There is not much to say here. Here is a couple of bindings you might have tried.
<PRE>
bind . <Control-Key-a> {puts a}
bind . <Control-Key-A> {puts A}
</PRE>
<P> <A> <A NAME="Sol11.4c">
<STRONG> Solution To Exercise 11.4c</STRONG> </A> <P>
The <TT>.edit_button</TT> command does not exist until the <TT>.edit_button</TT> widget
is created. The effect would be an invalid command name error.
<P> <A> <A NAME="Sol11.4d">
<STRONG> Solution To Exercise 11.4d</STRONG> </A> <P>
No problem. However, the event handler will not be evaluated until a Tab input
event is handled and that cannot be until after the initialization script has
finished.
<!-- 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="11.6.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/11.6.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="11.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/11.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 + -