Menu

#3039 bg change fg sometimes in Aqua menus

open
5
2012-11-20
2012-11-20
No

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!

Discussion

  • Russell Owen

    Russell Owen - 2012-11-20

    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"

     
  • Russell Owen

    Russell Owen - 2012-11-20
    • summary: bg change fg sometimes in Aqua menus --> Setting bg sometimes changes fg in Aqua menus
     
  • Kevin Walzer

    Kevin Walzer - 2012-11-20
    • summary: Setting bg sometimes changes fg in Aqua menus --> bg change fg sometimes in Aqua menus
     
  • Kevin Walzer

    Kevin Walzer - 2012-11-20

    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.

     
  • Kevin Walzer

    Kevin Walzer - 2012-11-20
    • assigned_to: das --> wordtech
     
  • Russell Owen

    Russell Owen - 2012-11-20

    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.

     
  • Kevin Walzer

    Kevin Walzer - 2012-11-20

    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.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.