Keyboard Traversal

The default bindings for menus allow for keyboard selection of menu entries. The selection process is started by pressing <Alt-x>, where x is the distinguishing letter for a menubutton. The underline attribute of a menubutton is used to highlight the appropriate letter. The underline value is a number that specifies a character position, and the count starts at zero. For example, a File menu with a highlighted F is created like this:

menubutton .menubar.file -text File -underline 0 \
    -menu .menubar.file.m

When the user types <Alt-f> over the main window, the menu is posted. The case of the highlighted letter is not important.

After a menu is posted, the arrow keys change the selected entry. The <Up> and <Down> keys move within ...

Get Practical Programming in Tcl & Tk, Third Edition 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.