Tk Source Code

View Ticket
Login
Ticket UUID: 844c0be72d433c24441926eb8a84bda1e9cbee72
Title: Menu entry underline does not consider activeborderwidth
Type: Bug Version: 8.6.13
Submitter: rtommy Created on: 2024-12-16 12:54:16
Subsystem: 13. Win Menus Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2025-01-03 23:39:31
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2025-01-03 23:39:31
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).

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()
User Comments: jan.nijtmans added on 2025-01-03 23:39:31:

Yes, I think this should be backported to both 8.7 and 8.6, so that's done now.

Thanks, François!


fvogel added on 2024-12-17 21:07:02:
Of course. From where do you think I took inspiration for the fix since Emiliano reported that X1 works correctly? :-)

Now merged in trunk. If someone wants to backport, just treat yourself.

jan.nijtmans added on 2024-12-17 10:00:59:

+1

I compared the code with tclUnixMenu.c, your change makes tclWinMenu.c handle it the same way. No further remarks, just go ahead!


fvogel added on 2024-12-16 21:36:10:

Fixed in [088283d026].

Thanks for the very good bug report and script (and translation into Tcl/Tk), it helped in finding the cause. Only Windows was affected.


emiliano added on 2024-12-16 16:16:00:
The equivalent Tcl script is

package require Tk
menu .mnu

menu .mnu.abw1 -tearoff false -activeborderwidth 1 -borderwidth 1
.mnu add cascade -menu .mnu.abw1 -label ActiveBW1 -underline 0
.mnu.abw1 add command -label "Menu Item 1" -underline 0 -accelerator Ctrl-1
.mnu.abw1 add command -label "Menu Item 2" -underline 0 -accelerator Ctrl-2

menu .mnu.abw4 -tearoff false -activeborderwidth 4 -borderwidth 4
.mnu add cascade -menu .mnu.abw4 -label "ActiveBW4" -underline 0
.mnu.abw4 add command -label "Menu Item 3" -underline 0 -accelerator Ctrl-3
.mnu.abw4 add command -label "Menu Item 4" -underline 0 -accelerator Ctrl-4

. configure -menu .mnu


Works correctly on X11; see attached screenshot

Attachments: