From Vasilis.Vlachoudis at cern.ch Wed Sep 13 11:57:10 2023 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 13 Sep 2023 15:57:10 +0000 Subject: [Tkinter-discuss] Navigation in menu with multiple columns Message-ID: In my application I am dynamically creating cascading menus, where some of them have multiple entries. To imrpove the visualization I break them into multiple columns using the "columnbreak=1" attribute in the Menu.add_command() The Up/Down keys move correctly the active/highlighted entry up/down However the Left key closes always the cascade submenu, while I would prefer to highlight the entry on the left column, and when it is on the left-most column to close the cascade submenu Is there a way to bind the Left/Right keys to move left/right in the columns? Vasilis -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Sep 14 03:45:36 2023 From: klappnase at web.de (Michael Lange) Date: Thu, 14 Sep 2023 09:45:36 +0200 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: References: Message-ID: <20230914094536.c907cedc07b287a6aee9c903@web.de> Hi Vasilis, On Wed, 13 Sep 2023 15:57:10 +0000 Vasilis Vlachoudis wrote: > In my application I am dynamically creating cascading menus, where some > of them have multiple entries. To imrpove the visualization I break > them into multiple columns using the "columnbreak=1" attribute in the > Menu.add_command() > > The Up/Down keys move correctly the active/highlighted entry up/down > > However the Left key closes always the cascade submenu, while I would > prefer to highlight the entry on the left column, and when it is on the > left-most column to close the cascade submenu Is there a way to bind > the Left/Right keys to move left/right in the columns? > > Vasilis could you please post a simple example that shows this behaviour? Have a nice day, Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Peace was the way. -- Kirk, "The City on the Edge of Forever", stardate unknown From Vasilis.Vlachoudis at cern.ch Fri Sep 15 05:55:49 2023 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 15 Sep 2023 09:55:49 +0000 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: <20230914094536.c907cedc07b287a6aee9c903@web.de> References: <20230914094536.c907cedc07b287a6aee9c903@web.de> Message-ID: Hi Michael, here is a snipped of a code and what I've managed up to now Mouse left click opens a standard menu with columns Mouse right click opens the same menu with columns and my first try to create a Left/Right keyboard bindings to navigate in the columns. My attempt fails on the first row and the last column... best Vasilis import tkinter as tk # ------------------------------------------------------------------------------ # Right key menu handler # ------------------------------------------------------------------------------ def menuRight(event): ??????menu = event.widget ??????index = menu.index(tk.ACTIVE) ??????last = menu.index(tk.LAST) ??????ypos = menu.yposition(index) ??????yprev = ypos ??????for i in range(index+1, last): ????????????if yprev < ypos <= menu.yposition(i): ??????????????????# WARNING empty entries appear as command without a label! ??????????????????# ignore them ??????????????????if menu.entrycget(i,"label") != "": ????????????????????????menu.activate(i) ??????????????????return "break" ????????????yprev = menu.yposition(i) # ------------------------------------------------------------------------------ # Left key menu handler # ------------------------------------------------------------------------------ def menuLeft(event): ??????menu = event.widget ??????index = menu.index(tk.ACTIVE) ??????ypos = menu.yposition(index) ??????yprev = ypos ??????for i in range(index-1, -1, -1): ????????????if menu.yposition(i) <= ypos < yprev: ??????????????????# WARNING empty entries appear as command without a label! ??????????????????# ignore them ??????????????????if menu.entrycget(i,"label") != "": ????????????????????????menu.activate(i) ??????????????????return "break" ????????????yprev = menu.yposition(i) #------------------------------------------------------------------------------- def show_menu(event, with_binding): ??????global root ??????menu = tk.Menu(root) ??????for label in ["one","two","three","four"]: ????????????submenu = tk.Menu(menu) ????????????menu.add_cascade(label=label, menu=submenu) ????????????for i in range(101): ??????????????????submenu.add_command(label=f"Item #{i}") ??????????????????if i and i%20==0: ????????????????????????submenu.entryconfigure(i, columnbreak=1) ????????????if with_binding: ??????????????????submenu.bind("", menuRight) ??????????????????submenu.bind("", menuLeft) ??????if with_binding: ????????????menu.bind("", menuRight) ????????????menu.bind("", menuLeft) ??????menu.tk_popup(event.x_root, event.y_root) #------------------------------------------------------------------------------- if __name__ == "__main__": ??????root = tk.Tk() ??????tk.Label(root, text="<1> Left click to show menu without Left/Right binding").pack() ??????tk.Label(root, text="<3> Right click to show menu with Left/Right binding").pack() ??????tk.Label(root, text=" to exit").pack() ??????root.bind("<1>", lambda e: show_menu(e,False)) ??????root.bind("<3>", lambda e: show_menu(e,True)) ??????root.bind("", lambda e: root.destroy()) ??????root.mainloop() ________________________________ From: Tkinter-discuss on behalf of Michael Lange Sent: Thursday 14 September 2023 09:45 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Navigation in menu with multiple columns Hi Vasilis, On Wed, 13 Sep 2023 15:57:10 +0000 Vasilis Vlachoudis wrote: > In my application I am dynamically creating cascading menus, where some > of them have multiple entries. To imrpove the visualization I break > them into multiple columns using the "columnbreak=1" attribute in the > Menu.add_command() > > The Up/Down keys move correctly the active/highlighted entry up/down > > However the Left key closes always the cascade submenu, while I would > prefer to highlight the entry on the left column, and when it is on the > left-most column to close the cascade submenu Is there a way to bind > the Left/Right keys to move left/right in the columns? > > Vasilis could you please post a simple example that shows this behaviour? Have a nice day, Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Peace was the way. -- Kirk, "The City on the Edge of Forever", stardate unknown _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sat Sep 16 20:14:15 2023 From: klappnase at web.de (Michael Lange) Date: Sun, 17 Sep 2023 02:14:15 +0200 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: References: <20230914094536.c907cedc07b287a6aee9c903@web.de> Message-ID: <20230917021415.b0167f918355715197435b35@web.de> Hi Vasilis, On Fri, 15 Sep 2023 09:55:49 +0000 Vasilis Vlachoudis wrote: > Hi Michael, > > here is a snipped of a code and what I've managed up to now thanks, I get your point now :-) I toyed around with your example a bit and came up with a custom menu class (see below; for testing I added a few useless separators and another submenu to the demo code). It's far from being perfect, but at least the keyboard navigation appears to work (It might require more thorough testing, though. Separators appear to be especially tricky.). Just for the fun of it I also added keybindings for the PageUp, PageDown, Home and End keys, which I thought might come in handy when dealing with huge submenus. Have a nice day, Michael ################################################################ import tkinter class GriddedMenu(tkinter.Menu): '''Menu with lots of menu items arranged in a grid.''' # TODO: insert(), delete(), add_cascade(), add_checkbutton(), # add_radiobutton(), add_separator(), configure() def __init__(self, parent, numrows=20, **kw): tkinter.Menu.__init__(self, parent, **kw) self.numrows = numrows self._curindex = -1 if self.type(0) == 'tearoff': self._curindex = 0 self.bind("", self._on_key_right) self.bind("", self._on_key_left) self.bind("", self._on_key_pageup) self.bind("", self._on_key_pagedown) self.bind("", self._on_key_home) self.bind("", self._on_key_end) def add_cascade(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_cascade(self, **kw) self._curindex += 1 def add_command(self, **kw): tkinter.Menu.add_command(self, **kw) self._curindex += 1 if (self._curindex >= self.numrows) and \ (self._curindex % self.numrows == 0): self.entryconfigure(self._curindex, columnbreak=1) def add_separator(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_separator(self, **kw) self._curindex += 1 def _on_key_left(self, event): index = self.index('active') if index - self.numrows >= 0: newindex = index - self.numrows while (newindex >= 0) and (self.type(newindex) == 'separator'): newindex -= self.numrows if newindex >= 0: self.activate(newindex) return 'break' def _on_key_right(self, event): index = self.index('active') end = self.index('end') if index + self.numrows <= end: newindex = index + self.numrows while (newindex <= end) and (self.type(newindex) == 'separator'): newindex += self.numrows if newindex <= end: self.activate(newindex) return 'break' def _on_key_pageup(self, event): index = self.index('active') row = index % self.numrows newindex = index - row while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_pagedown(self, event): index = self.index('active') row = index % self.numrows newindex = min(self.index('end'), index + (self.numrows - row - 1)) while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) def _on_key_home(self, event): newindex = 0 while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_end(self, event): newindex = self.index('end') while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) #------------------------------------------------------------------------------ if __name__ == "__main__": def show_menu(event): menu = tkinter.Menu(tearoff=0) for label in ["one","two","three","four"]: submenu = GriddedMenu(menu) menu.add_cascade(label=label, menu=submenu) for i in range(8): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(8, 57): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(57, 72): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(72, 101): submenu.add_command(label=f"Item #{i}") submenu.add_separator() subsubmenu = tkinter.Menu(submenu) submenu.add_cascade(label='foo', menu=subsubmenu) subsubmenu.add_command(label='bar') submenu.add_separator() menu.tk_popup(event.x_root, event.y_root) root = tkinter.Tk() tkinter.Label(root, text="<1> Left click to show menu").pack() tkinter.Label(root, text=" to exit").pack() root.bind("<1>", show_menu) root.bind("", lambda e: root.destroy()) root.mainloop() ############################################################################### From Vasilis.Vlachoudis at cern.ch Mon Sep 18 03:42:23 2023 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 18 Sep 2023 07:42:23 +0000 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: <20230917021415.b0167f918355715197435b35@web.de> References: <20230914094536.c907cedc07b287a6aee9c903@web.de> <20230917021415.b0167f918355715197435b35@web.de> Message-ID: Great, many thanks Michael! ________________________________ From: Michael Lange Sent: Sunday 17 September 2023 02:14 To: Vasilis Vlachoudis Cc: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Navigation in menu with multiple columns Hi Vasilis, On Fri, 15 Sep 2023 09:55:49 +0000 Vasilis Vlachoudis wrote: > Hi Michael, > > here is a snipped of a code and what I've managed up to now thanks, I get your point now :-) I toyed around with your example a bit and came up with a custom menu class (see below; for testing I added a few useless separators and another submenu to the demo code). It's far from being perfect, but at least the keyboard navigation appears to work (It might require more thorough testing, though. Separators appear to be especially tricky.). Just for the fun of it I also added keybindings for the PageUp, PageDown, Home and End keys, which I thought might come in handy when dealing with huge submenus. Have a nice day, Michael ################################################################ import tkinter class GriddedMenu(tkinter.Menu): '''Menu with lots of menu items arranged in a grid.''' # TODO: insert(), delete(), add_cascade(), add_checkbutton(), # add_radiobutton(), add_separator(), configure() def __init__(self, parent, numrows=20, **kw): tkinter.Menu.__init__(self, parent, **kw) self.numrows = numrows self._curindex = -1 if self.type(0) == 'tearoff': self._curindex = 0 self.bind("", self._on_key_right) self.bind("", self._on_key_left) self.bind("", self._on_key_pageup) self.bind("", self._on_key_pagedown) self.bind("", self._on_key_home) self.bind("", self._on_key_end) def add_cascade(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_cascade(self, **kw) self._curindex += 1 def add_command(self, **kw): tkinter.Menu.add_command(self, **kw) self._curindex += 1 if (self._curindex >= self.numrows) and \ (self._curindex % self.numrows == 0): self.entryconfigure(self._curindex, columnbreak=1) def add_separator(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_separator(self, **kw) self._curindex += 1 def _on_key_left(self, event): index = self.index('active') if index - self.numrows >= 0: newindex = index - self.numrows while (newindex >= 0) and (self.type(newindex) == 'separator'): newindex -= self.numrows if newindex >= 0: self.activate(newindex) return 'break' def _on_key_right(self, event): index = self.index('active') end = self.index('end') if index + self.numrows <= end: newindex = index + self.numrows while (newindex <= end) and (self.type(newindex) == 'separator'): newindex += self.numrows if newindex <= end: self.activate(newindex) return 'break' def _on_key_pageup(self, event): index = self.index('active') row = index % self.numrows newindex = index - row while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_pagedown(self, event): index = self.index('active') row = index % self.numrows newindex = min(self.index('end'), index + (self.numrows - row - 1)) while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) def _on_key_home(self, event): newindex = 0 while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_end(self, event): newindex = self.index('end') while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) #------------------------------------------------------------------------------ if __name__ == "__main__": def show_menu(event): menu = tkinter.Menu(tearoff=0) for label in ["one","two","three","four"]: submenu = GriddedMenu(menu) menu.add_cascade(label=label, menu=submenu) for i in range(8): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(8, 57): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(57, 72): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(72, 101): submenu.add_command(label=f"Item #{i}") submenu.add_separator() subsubmenu = tkinter.Menu(submenu) submenu.add_cascade(label='foo', menu=subsubmenu) subsubmenu.add_command(label='bar') submenu.add_separator() menu.tk_popup(event.x_root, event.y_root) root = tkinter.Tk() tkinter.Label(root, text="<1> Left click to show menu").pack() tkinter.Label(root, text=" to exit").pack() root.bind("<1>", show_menu) root.bind("", lambda e: root.destroy()) root.mainloop() ############################################################################### -------------- next part -------------- An HTML attachment was scrubbed... URL: From Vasilis.Vlachoudis at cern.ch Tue Sep 19 05:34:34 2023 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 19 Sep 2023 09:34:34 +0000 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: References: <20230914094536.c907cedc07b287a6aee9c903@web.de> <20230917021415.b0167f918355715197435b35@web.de> Message-ID: 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" * 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. import tkinter as tk #------------------------------------------------------------------------------- def show_menu(event): ??????global root ??????menu = tk.Menu(root) ??????for label in ["one","two","three","four"]: ????????????submenu = tk.Menu(menu) ????????????menu.add_cascade(label=label, menu=submenu) ????????????for i in range(101): ??????????????????sub2menu = tk.Menu(submenu) ??????????????????sublabel = f"Item #{i}" ??????????????????submenu.add_cascade(label=sublabel,menu=sub2menu) ??????????????????if i and i%20==0: ????????????????????????submenu.entryconfigure(i, columnbreak=1) ??????????????????for j in range(10): ????????????????????????sub2menu.add_command(label=f"{sublabel} : {j}") ??????menu.tk_popup(event.x_root, event.y_root) #------------------------------------------------------------------------------- if __name__ == "__main__": ??????root = tk.Tk() ??????tk.Label(root, text="<1> Left click to show menu").pack() ??????tk.Label(root, text=" to exit").pack() ??????root.bind("<1>", lambda e: show_menu(e)) ??????root.bind("<3>", lambda e: show_menu(e)) ??????root.bind("", lambda e: show_menu(e)) ??????root.bind("", lambda e: root.destroy()) ??????root.mainloop() ________________________________ From: Vasilis Vlachoudis Sent: Monday 18 September 2023 09:42 To: Michael Lange Cc: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Navigation in menu with multiple columns Great, many thanks Michael! ________________________________ From: Michael Lange Sent: Sunday 17 September 2023 02:14 To: Vasilis Vlachoudis Cc: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Navigation in menu with multiple columns Hi Vasilis, On Fri, 15 Sep 2023 09:55:49 +0000 Vasilis Vlachoudis wrote: > Hi Michael, > > here is a snipped of a code and what I've managed up to now thanks, I get your point now :-) I toyed around with your example a bit and came up with a custom menu class (see below; for testing I added a few useless separators and another submenu to the demo code). It's far from being perfect, but at least the keyboard navigation appears to work (It might require more thorough testing, though. Separators appear to be especially tricky.). Just for the fun of it I also added keybindings for the PageUp, PageDown, Home and End keys, which I thought might come in handy when dealing with huge submenus. Have a nice day, Michael ################################################################ import tkinter class GriddedMenu(tkinter.Menu): '''Menu with lots of menu items arranged in a grid.''' # TODO: insert(), delete(), add_cascade(), add_checkbutton(), # add_radiobutton(), add_separator(), configure() def __init__(self, parent, numrows=20, **kw): tkinter.Menu.__init__(self, parent, **kw) self.numrows = numrows self._curindex = -1 if self.type(0) == 'tearoff': self._curindex = 0 self.bind("", self._on_key_right) self.bind("", self._on_key_left) self.bind("", self._on_key_pageup) self.bind("", self._on_key_pagedown) self.bind("", self._on_key_home) self.bind("", self._on_key_end) def add_cascade(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_cascade(self, **kw) self._curindex += 1 def add_command(self, **kw): tkinter.Menu.add_command(self, **kw) self._curindex += 1 if (self._curindex >= self.numrows) and \ (self._curindex % self.numrows == 0): self.entryconfigure(self._curindex, columnbreak=1) def add_separator(self, **kw): # FIXME: handle columnbreaks tkinter.Menu.add_separator(self, **kw) self._curindex += 1 def _on_key_left(self, event): index = self.index('active') if index - self.numrows >= 0: newindex = index - self.numrows while (newindex >= 0) and (self.type(newindex) == 'separator'): newindex -= self.numrows if newindex >= 0: self.activate(newindex) return 'break' def _on_key_right(self, event): index = self.index('active') end = self.index('end') if index + self.numrows <= end: newindex = index + self.numrows while (newindex <= end) and (self.type(newindex) == 'separator'): newindex += self.numrows if newindex <= end: self.activate(newindex) return 'break' def _on_key_pageup(self, event): index = self.index('active') row = index % self.numrows newindex = index - row while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_pagedown(self, event): index = self.index('active') row = index % self.numrows newindex = min(self.index('end'), index + (self.numrows - row - 1)) while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) def _on_key_home(self, event): newindex = 0 while self.type(newindex) == 'separator': newindex += 1 self.activate(newindex) def _on_key_end(self, event): newindex = self.index('end') while self.type(newindex) == 'separator': newindex -= 1 self.activate(newindex) #------------------------------------------------------------------------------ if __name__ == "__main__": def show_menu(event): menu = tkinter.Menu(tearoff=0) for label in ["one","two","three","four"]: submenu = GriddedMenu(menu) menu.add_cascade(label=label, menu=submenu) for i in range(8): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(8, 57): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(57, 72): submenu.add_command(label=f"Item #{i}") submenu.add_separator() for i in range(72, 101): submenu.add_command(label=f"Item #{i}") submenu.add_separator() subsubmenu = tkinter.Menu(submenu) submenu.add_cascade(label='foo', menu=subsubmenu) subsubmenu.add_command(label='bar') submenu.add_separator() menu.tk_popup(event.x_root, event.y_root) root = tkinter.Tk() tkinter.Label(root, text="<1> Left click to show menu").pack() tkinter.Label(root, text=" to exit").pack() root.bind("<1>", show_menu) root.bind("", lambda e: root.destroy()) root.mainloop() ############################################################################### -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sat Sep 23 13:08:04 2023 From: klappnase at web.de (Michael Lange) Date: Sat, 23 Sep 2023 19:08:04 +0200 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: References: <20230914094536.c907cedc07b287a6aee9c903@web.de> <20230917021415.b0167f918355715197435b35@web.de> Message-ID: <20230923190804.a68abbb3e3d0315e78eb25ce@web.de> Hi, On Tue, 19 Sep 2023 09:34:34 +0000 Vasilis Vlachoudis 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" > * 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 From Vasilis.Vlachoudis at cern.ch Mon Sep 25 04:05:23 2023 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 25 Sep 2023 08:05:23 +0000 Subject: [Tkinter-discuss] Navigation in menu with multiple columns In-Reply-To: <20230923190804.a68abbb3e3d0315e78eb25ce@web.de> References: <20230914094536.c907cedc07b287a6aee9c903@web.de> <20230917021415.b0167f918355715197435b35@web.de> <20230923190804.a68abbb3e3d0315e78eb25ce@web.de> Message-ID: Great! Many thanks Michael! ________________________________ From: Michael Lange Sent: Saturday 23 September 2023 19:08 To: Vasilis Vlachoudis Cc: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Navigation in menu with multiple columns Hi, On Tue, 19 Sep 2023 09:34:34 +0000 Vasilis Vlachoudis 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" > * 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: