Tk Source Code

View Ticket
Login
2022-02-25
07:56 Closed ticket [3588636f]: bg change fg sometimes in Aqua menus plus 9 other changes artifact: 9a84a018 user: chrstphrchvz
2020-11-18
21:23 Ticket [635167af] Aqua: some menu entries' text and bitmaps (again) are black by default status still Open with 4 other changes artifact: 43e8e1aa user: marc_culler
15:33 Ticket [635167af]: 3 changes artifact: e37e1a19 user: chrstphrchvz
2020-11-17
22:15 Ticket [635167af]: 4 changes artifact: a2cf5e79 user: marc_culler
2019-08-15
09:38 Ticket [4880fc12] Aqua: bitmaps in menu entries are black by default status still Open with 6 other changes artifact: 6848da73 user: chrstphrchvz
2019-08-11
23:39 Ticket [51054929] Undocumented effects of menu entry color options on aqua status still Open with 4 other changes artifact: 7fdc857b user: chrstphrchvz
2012-11-20
08:44 Ticket [3588636f] bg change fg sometimes in Aqua menus status still Open with 4 other changes artifact: 214de746 user: wordtech
08:28 Ticket [3588636f]: 4 changes artifact: a4a952a2 user: reowen
08:17 Ticket [3588636f]: 1 change artifact: 5326809b user: wordtech
08:16 Ticket [3588636f]: 5 changes artifact: 70108b98 user: wordtech
07:48 Ticket [3588636f]: 5 changes artifact: 263d64d1 user: reowen
00:45 New ticket [3588636f]. artifact: af1035ae user: reowen

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"