| 11.7 Solutions to Exercises |
|
|
There is no answer to give for this question.
Both command and variable substitution would happen during initialization. The event handler for .edit_button would simply reset Entry to the empty string each time it is executed. In Script S11.1a, the variable named Entry is not evaluated in the command that creates .edit_button. The script that is declared with the -commmand option will be executed in the top-level namespace, if and when it is executed. This means that Entry refers to a top-level variable without being declared with global.
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]
The phrase "That tickles!" is repeatedly written in the command window as the mouse moves over any part of the root window except the .quit_button widget. The reason is that although both bindings apply to the .quit_button widget, the binding whose event handler is simply break fires first. This causes any other applicable bindings to be skipped. 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. There is not much to say here. Here is a couple of bindings you might have tried.
bind . <Control-Key-a> {puts a}
bind . <Control-Key-A> {puts A}
The .edit_button command does not exist until the .edit_button widget is created. The effect would be an invalid command name error. 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. |
Author's Home Page |
|
Order from Amazon. |