Description
Bug report
Bug description:
This issue is related to underline
attribute of a menu item command.
When the Menu has activeborderwidth
bigger than 1 and the menu item has underline
, the position of the actual text (character) underline does not consider activeborderwidth
and the _
is not under the character where it should be (text shifted by activeborderwidth
). Screenshot is below.
It seems to be an issue with Tcl/Tk itself therefore, I raised a ticket there: 844c0be72d433c24441926eb8a84bda1e9cbee72

Example python code: compare menu items under ActiveBW1
and ActiveBW4
.
from tkinter import *
root = Tk()
menu = Menu(root)
abw1 = Menu(menu, tearoff=0, activeborderwidth=1, borderwidth=1)
menu.add_cascade(menu=abw1, label='ActiveBW1', underline=0)
abw1.add_command(label='Menu Item 1', underline=0, accelerator='Ctrl-1')
abw1.add_command(label='Menu Item 2', underline=0, accelerator='Ctrl-2')
abw4 = Menu(menu, tearoff=0, activeborderwidth=4, borderwidth=4)
menu.add_cascade(menu=abw4, label='ActiveBW4', underline=0)
abw4.add_command(label='Menu Item 3', underline=0, accelerator='Ctrl-3')
abw4.add_command(label='Menu Item 4', underline=0, accelerator='Ctrl-4')
root.config(menu=menu)
root.mainloop()
(The example above is not the best since the Menu names have the same first letter, and the item names too)
However, I believe there could be a workaround to actually achieve the same behaviour without using underline
.
I don't need the actual character underline, but I would need the keyboard shortcut.
How can I add keyboard shortcut bindings for the logic of: select Menu and the item?
In the following example I can select menu items by keyboard shorcuts:
Alt-o
theno
results showinfo "1"Alt-o
thent
results showinfo "2"Alt-t
thent
results showinfo "3"Alt-t
thenf
results showinfo "4"
Note, accelerators are not really considered.
root = Tk()
menu = Menu(root)
abw1 = Menu(menu, tearoff=0, activeborderwidth=1, borderwidth=1)
menu.add_cascade(menu=abw1, label='One', underline=0)
abw1.add_command(label='one', underline=0, accelerator='Ctrl-1', command=lambda: showinfo("1","1"))
abw1.add_command(label='two', underline=0, accelerator='Ctrl-2', command=lambda: showinfo("2","2"))
abw4 = Menu(menu, tearoff=0, activeborderwidth=4, borderwidth=4)
menu.add_cascade(menu=abw4, label='Two', underline=0)
abw4.add_command(label='three', underline=0, accelerator='Ctrl-3', command=lambda: showinfo("3","3"))
abw4.add_command(label='four', underline=0, accelerator='Ctrl-4', command=lambda: showinfo("4","4"))
root.config(menu=menu)
root.mainloop()
I would need the same result by adding bindings and without using underline
(since it has the original fault mention at the beginning).
I want to 'open' the Menu first and then select an item, all with shortcuts.
CPython versions tested on:
3.12
Operating systems tested on:
Windows