Tk Source Code

View Ticket
Login
Ticket UUID: 9fcef965a54fea446d1cb99324a56047a343970a
Title: macOS aqua: certain menu entries' text color always black
Type: Bug Version: 8.6.8
Submitter: chrstphrchvz Created on: 2018-08-01 16:47:10
Subsystem: 11. Aqua Menus Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2019-03-01 12:17:49
Resolution: Invalid Closed By: chrstphrchvz
    Closed on: 2019-03-01 12:17:49
Description:

Sometimes the text color for entries in menus and menubuttons is always black without -foreground or -background having been explicitly set. The expected behavior is that entries' text color when unhighlighted is either black or white depending on whether the dark menu bar is enabled in System Preferences, and white if the entry is highlighted/hovered over.

The impairments to usability are that the black text of a highlighted entry does not contrast well with the blue region; and that if the dark menu bar is enabled, then unhighlighted entries are completely unreadable.

I found this while using Tcl::pTk Perl module; the issue is reproducible using its widgetTclpTk demo program (from the menus.pl and menus2.pl demos) (see https://rt.cpan.org/Public/Bug/Display.html?id=125049):

Screenshot of widgetTclpTk menus.pl demo, light menu bar Screenshot of widgetTclpTk menus2.pl demo, light menu bar

I also observed this in Gitk, which is a pure Tcl/Tk program:

Screenshot of Gitk, dark menu bar

I haven't come up with a minimal test case that exhibits this issue, so I might not have ruled out that this isn't caused by whatever is using Tcl/Tk rather than by Tcl/Tk itself. I don't observe this issue in Tcl/Tk's widget demo program (menu and menubu).

I have observed this both with the included Tcl/Tk 8.5.9 in recent macOS as well as Tcl/Tk 8.6.8 (from MacPorts' tk +aqua port variant). I am using macOS 10.13.6.

I'm not familiar with the Tk source, but I would appreciate any suggestions on where to look. Feel free to update this description with more precise verbiage.

User Comments: chrstphrchvz added on 2019-03-01 12:17:49:

I finally found the cause (though not yet a solution) for this issue in Tcl::pTk. It must not have occurred to me earlier to heed the documentation for menu, specifically the part where it says:

If this option is specified as an empty string (the default), then the (-background/-foreground/etc.) option for the overall menu is used.

So once I checked cget on the menus rather than the entries, it indicated non-default colors were set. Based on which colors they were being set to, I quickly found the code in Tcl::pTk responsible.

I'll go ahead and close this ticket.


kevin_walzer added on 2018-08-13 11:44:17:
When you do not configure the menu entries, cget -foreground won't return anything, because the native coloring is used; Tk does not know about this nor register it.

The behavior you are seeing is not present in the Tcl/Tk versions of these demos--as I expect. Therefore, I can only conclude the issue is somewhere in your code, which I assume is re-implementing these demos in Perl. I've done some work with Perl's Tkx module, but not with Perl-Tk directly, nor with the wrapper library you are working with, so I'm not sure where to point you. 

Your Tcl::pTk seems a great project, bridging all that legacy Perl-Tk code into the modern Tcl/Tk world. Thanks for that!

chrstphrchvz added on 2018-08-13 10:52:17:

Some more observations I've made: if I have not manually set a -foreground or -background for an item, then doing cget -foreground or cget -background does not return a color for both the correctly and incorrectly behaving entries (Q: does this prove that the scripts were not setting a color?). But if I have specifically attempted to set the either of those colors, then cget does return the color I specified. However it only actually changes the color for:

  1. the entries that were behaving correctly to begin with, using either -foreground or -background (they have the same effect, but -foreground is more consistent with what Tk documents for other windowingsystems); and
  2. the entries not behaving correctly, though only with -foreground (i.e. -background does not have a visible effect)
I've also verified that in all cases -activeforeground and -activebackground have no visble effect on aqua.

For the following screenshots, "Print hello" is a correctly behaving entry, and "See current values" is an incorrectly behaving entry.

Screenshot with -foreground set for both of those entries:

Screenshot with -background set for both entries:


kevin_walzer added on 2018-08-13 02:12:32:
The menus on macOS always highlight when selected natively; that is the default if their appearance is not configured at the script level in Tk. The screenshots you show suggest to me that there is some configuration going on somewhere in your script. There is no need to set font, size, color, etc. anywhere in Tk menus on macOS unless you have a specific reason.