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 N
th 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.
The default value for -underline
is -1, which
means no characters will be underlined in the text string.
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.