Re: Accelerators (key bindings) and tabs



Twylite wrote:

We have an application with multiple pages/tabs (PageControl,
TabControl, Notebook, call it what you may). On some of those tabs we
have buttons and labels that have accelerator indicators. To make
those accelerators work one normally binds the key combination to the
toplevel -- but with multiple pages/tabs this allows key combinations
to invoke actions on widgets that aren't on the displayed tab. How do
I resolve this?


The "keynav" package in Tile (undocumented except for comments
in the source file, but otherwise supported) can help with this.

See here:

http://tktable.cvs.sourceforge.net/*checkout*/tktable/tile/library/keynav.tcl?revision=1.8

Basic usage is:

keynav::enableMnemonics $top

That adds an <Alt-KeyPress> binding to the specified toplevel
that will enable mnemonic activation for all widgets in that toplevel.
You usually don't need to do anything else other than setting
the "-underline" option on individual widgets.

Mnemonic activation works for any viewable widget that has
"-text" and "-underline" options and a binding for the <<Invoke>>
virtual event. (The keynav package adds <<Invoke>> bindings for
Button, Checkbutton, and Radiobutton widgets; tile widgets have
support built in.)

[keynav::enableMnemonics] doesn't work for ttk::notebook widgets --
the widget doesn't have "-text" and "-underline" options, only the tabs do --
but it's compatible with [ttk::notebook::enableTraversal].
In particular, it will only invoke widgets on the current tab,
as desired.


--Joe English
.