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: (text/html)
<p>Sometimes the text color for entries in menus and menubuttons is always black without <code>-foreground</code> or <code>-background</code> 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.</p>

<p>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.</p>

<p>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 <a href="https://rt.cpan.org/Public/Bug/Display.html?id=125049">https://rt.cpan.org/Public/Bug/Display.html?id=125049</a>):</p>
<img src="https://user-images.githubusercontent.com/7941193/37901465-e33f2f5a-30b6-11e8-8d22-dff8bfdea0f2.png" title="Screenshot of widgetTclpTk menus.pl demo, light menu bar" alt="Screenshot of widgetTclpTk menus.pl demo, light menu bar" />
<img src="https://user-images.githubusercontent.com/7941193/37901456-dede130e-30b6-11e8-85c4-1539471fd5a0.png" title="Screenshot of widgetTclpTk menus2.pl demo, light menu bar" alt="Screenshot of widgetTclpTk menus2.pl demo, light menu bar" />
<p>I also observed this in Gitk, which is a pure Tcl/Tk program:</p>
<img src="https://rt.cpan.org/Ticket/Attachment/1795332/965524/" title="Screenshot of Gitk, dark menu bar" alt="Screenshot of Gitk, dark menu bar" />


<p>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).</p>
<p>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' <code>tk +aqua</code> port variant). I am using macOS 10.13.6.</p>


<p>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.</p>
User Comments: chrstphrchvz added on 2019-03-01 12:17:49: (text/x-fossil-wiki)
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 <code>menu</code>, specifically the part where it says:

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

So once I checked <code>cget</code> 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: (text/html)
<p>Some more observations I've made: if I have not manually set a <code>-foreground</code> or <code>-background</code> for an item, then doing <code>cget -foreground</code> or <code>cget -background</code> does not return a color for both the correctly and incorrectly behaving entries (<i>Q: does this prove that the scripts were not setting a color?</i>). But if I have specifically attempted to set the either of those colors, then <code>cget</code> does return the color I specified. However it only actually changes the color for:<ol>
<li>the entries that were behaving correctly to begin with, using either <code>-foreground</code> or <code>-background</code> (they have the same effect, but <code>-foreground</code> is more consistent with what Tk documents for other windowingsystems); and</li>
<li>the entries not behaving correctly, though only with <code>-foreground</code> (i.e. <code>-background</code> does not have a visible effect)</li>
</ol>
I've also verified that in all cases <code>-activeforeground</code> and <code>-activebackground</code> have no visble effect on aqua.
</p>
<p>
For the following screenshots, "Print hello" is a correctly behaving entry, and "See current values" is an incorrectly behaving entry.
</p>
<p>
  Screenshot with <code>-foreground</code> set for both of those entries:
</p>
<img src="https://rt.cpan.org/Ticket/Attachment/1799467/967716/" />
<p>
  Screenshot with <code>-background</code> set for both entries:
</p>
<img src="https://rt.cpan.org/Ticket/Attachment/1799467/967717/" />

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.