Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tk.Menu underline does not consider activeborderwidth #127988

Copy link
Copy link
Open
@rtommy

Description

@rtommy
Issue body actions

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

underline_issue

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 then o results showinfo "1"
  • Alt-o then t results showinfo "2"
  • Alt-t then t results showinfo "3"
  • Alt-t then f 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-tkintertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.