O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Example of -underline => 1

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required