[Tkinter-discuss] Navigation in menu with multiple columns
Michael Lange
klappnase at web.de
Sat Sep 23 13:08:04 EDT 2023
Hi,
On Tue, 19 Sep 2023 09:34:34 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:
> Using column breaks and sub-menus, makes navigation with the mouse
> almost impossible. e.g. with the code below
>
> * open the menu
> * hover the mouse over "one"
> * hover the mouse over "Item #40"
> * <Left-mouse-click> to select the submenu
> * ... try to select in the new submenu "Item #40 : 2" with the mouse
>
> I cannot, since when I hover the mouse over the other items their
> respective submenu opens. I can only selected it with the keyboard.
you can avoid this by calling
root.option_add('*Menu.clickToFocus', '1')
immediately after creating the main Tk window. This doesn't seem to be
documented, you can find the option in menu.tcl though.
It is in the following code block in the Tk function ::tk::MenuMotion :
set mode [option get $menu clickToFocus ClickToFocus]
if {[string is false $mode]} {
set delay [expr {[$menu cget -type] eq "menubar" ? 0 : 50}]
if {[$menu type $index] eq "cascade"} {
set Priv(menuActivatedTimer) \
[after $delay [list $menu postcascade active]]
} else {
set Priv(menuDeactivatedTimer) \
[after $delay [list $menu postcascade none]]
}
So you see, if clickToFocus evaluates True, the call to postcascade does not occur.
Have a nice day,
Michael
More information about the Tkinter-discuss
mailing list