Tk Source Code

View Ticket
Login
Ticket UUID: 3587262
Title: Width of menubutton too short on aqua with textvariable
Type: Bug Version: obsolete: 8.5.11
Submitter: reowen Created on: 2012-11-14 22:37:26
Subsystem: 03. [*button] and [label] Assigned To: wordtech
Priority: 5 Medium Severity:
Status: Pending Last Modified: 2026-10-08 12:39:11
Resolution: Out of Date Closed By:
    Closed on:
Description:
The attached code shows a bug in menubutton on MacOS (aqua): if I specify the font and use textvariable then the menubutton is displayed in a width that is far too narrow.

I tried to work around it using update idletasks and had no luck.

One workaround that does work is to change the font size in the option database and then change it back again. This causes an ugly display glitch but it's better than nothing.
User Comments: serhiy.storchaka added on 2026-10-08 12:39:11:

Since [6d9ba34985] (Tk 8.6.4) and the menubutton geometry rewrite for [70e531918e] (Tk 8.6.10), the size of a menubutton on macOS is computed from the text layout in the current font whenever the text variable changes. So this looks fixed. Could someone with a Mac confirm with the attached script?


reowen added on 2012-11-17 06:56:51:
The workaround I ended up with is as follows: if the user specifies a width of 0 then I add a callback that sets width whenever the menubutton text is changed This is slightly dangerous in that the user cannot manually change the width after constructing the menubutton, but works for my code. I was fortunate to be using a wrapper class, so I was able to add the patch in one place.

This appears to be a genuine bug, not just a platform-specific quirk, because:
- With a width of 0 surely the only sensible behavior is to display a menubutton that is wide enough to show all characters?
- Changing the font size and then changing it back causes the problem to go away (the menubutton suddenly is wide enough to see all the text). If it was a platform-specific quirk then the display would remain the same.

reowen added on 2012-11-15 05:37:26:

File Added - 456585: menubutton auto width bug.tcl

Attachments: