start page | rating of books | rating of authors | reviews | copyrights

Book HomeMastering Perl/TkSearch this book

4.14. Adding a Keyboard Mapping

A Button is traditionally invoked by clicking mouse button 1 when the mouse cursor is over the Button. It can also be invoked by pressing the Tab key until the Button has the keyboard focus, then pressing the spacebar. The effects are the same: the callback associated with the Button is called, and the Button -relief changes momentarily. The keyboard focus is indicated visually by a thin black rectangle drawn around the widget (see Figure 4-37, later in this chapter).

To allow an additional keyboard character to invoke the Button, use the -underline option in a Button displaying text:

-underline => N

This will underline the Nth character in the text string. The first character of the text string is the 0th character, so the text string "Exit", -underline => 1 will underline the second character in the string, the "x" (see Figure 4-31).

Don't forget to actually create the binding for the underlined character.

Figure 4-31

Figure 4-31. Example of -underline => 1

The default value for -underline is -1, which means no characters will be underlined in the text string.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.