Tk Source Code

View Ticket
Login
Ticket UUID: 3588636
Title: bg change fg sometimes in Aqua menus
Type: Bug Version: None
Submitter: reowen Created on: 2012-11-20 00:45:19
Subsystem: 11. Aqua Menus Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2022-02-25 07:56:16
Resolution: Fixed Closed By: chrstphrchvz
    Closed on: 2022-02-25 07:56:16
Description:
As of Tcl/Tk 8.5 the background option for menus affects the *foreground* color, not the background. Even stranger, it only affects the foreground color if foreground is not set. Once foreground is set the background is ignored.

Here is demo code:

tk_optionMenu .om var One Two Three
pack .om
.om.menu configure -bg "green"

At this point observe that the menu has green foreground text (and the normal white background).

.om.menu configure -fg "red"

Now change the foreground and observe that the text takes on the desired foreground color.

.om.menu configure -bg "green"

Now change the background and observe that the new color is ignored.

I doubt that the background color can be set on Aqua. If that is so, then please fix Aqua Tk so that menu ignores the background option. It should never be used to change the foreground color!
User Comments: chrstphrchvz added on 2022-02-25 07:56:16:

Closing: as of Tk 8.6.11 ([4e5bba9cee]), the background and foreground options for menu entries are ignored on Aqua, and are documented as such.


wordtech added on 2012-11-20 08:44:37:
Run wish from the command line. Under "file," select "Run widget demo." Look at the sample code under the "menu" category; you'll see a menu item called "color," which illustrates different colors. They are configured with different colors, and are set as the background color.

My guess is that Tk-Cocoa is designed this way to support the -bg or the -fg color in the only way the widget can, by configuring the foreground color. The classic configurable menu background isn't supported on Cocoa, at least as far as I can tell. 

I agree the behavior you are seeing isn't ideal, but I would suggest that setting the -bg flag as no-op would be worse.  And, as I noted, it would break code that is in the Tk demo. 

As implemented, the menu code looks first for the foreground, then the background; the foreground takes precedence. If you have to configure one of these flags on the Mac, just configure one and not both. 

As with the other bugs you've filed recently, I would suggest an easier solution: it is much simpler  and cleaner to respect the default implementation for the platform. At least in my view, Tk menus with non-platform-native fonts and colors are ugly and stick out like a sore thumb.

reowen added on 2012-11-20 08:28:22:
Which demo is this?

There are two aspects I don't understand:
- Why is it useful to be able to set a given property (the forground color of text in menus) using two opposite properties (fg and bg)? That seems a recipe for confusing both users and developers.
- Why it is useful that bg can sometimes set the foreground color of a menu (i.e. if fg has never been set) and sometimes it cannot (if fg has been set)? Surely it should be more consistent?

Of these two I am much more concerned about the first, but fixing the first would also fix the second.

wordtech added on 2012-11-20 08:16:16:
Implementing this change is straightforward from a technical standpoint, but it would break code in the Tcl/Tk demo that configures the color of a menu entry with the -bg flag. I think the behavior you are seeing is there by design.

reowen added on 2012-11-20 07:48:56:
I got the order of the comments and commands wrong in the latter bit. Here's a corrected version:

At this point observe that the menu has green foreground text (and the normal white background).

Now change the foreground and observe that the text takes on the desired foreground color.

.om.menu configure -fg "red"

Now change the background and observe that the new color is ignored.

.om.menu configure -bg "green"