The icons are hard-coded to be black and blend into the backgound:
Proposed solution
For wx and Qt, we modify the color to be light when a dark backgound is present; see the _icon() methods in these backends.
It would be nice to have something similar for Tk as well.
This needs somebody with knowledge in Tk. Marking as good first issue because one does not need to understand anything about Matplotlib. The button icon is set in NavigationToolbar2Tk._set_image_for_button().
@timhoffm not that straightforward in pure Tk, but since we're already using Pillow it's very easy. Did you set the background colour for the buttons manually, or is there some function that sets it? So I know where to check for the button background colour.
The icon background is transparent, so it effectively uses the theme background. We color the icon with the window text color. Relying on the theme colors will give a reasonable contrast and consistent look. See
@timhoffm Ah, I get what you're asking. Tk doesn't have a proper application-wide theme without using Ttk (that reminds me, I've been meaning to write a _backend_ttk when I have a few free days...), but I wrote up a quick fix in #22163 that checks the background colour of the button, and changes the icon colour to the button's text colour if the background's HSV Value is under 50%.
I've tested it briefly and it seems to work, but I don't have any realistic use-cases to test it with because in my app I've monkey-patched the backend to use ttk. Could you test it with any real-life cases you're aware of?
Also, question: is there a reason for limiting this to just dark themes?
Also, question: is there a reason for limiting this to just dark themes?
This was discovered and fixed for the specific case: "Our icons are hardly visible in dark themes, let's make them light there" #14810. This is the minimal workaround to fix the default icons and reduce the likelihood of messing up user icons. Let's move further discussion to #22164.
@QuLogic a toggle button can be created easily by using ttk.Checkbutton(..., style="Toolbutton"). The main reason I was considering this is because I wanted to write a Tk equivalent of qt_editor, for which I'd be using Ttk, and at that point it would be good to make the toolbar's look consistent with it. The only big difference between a Tk and Ttk toolbar would be how they respond to user themes though, so I'm not sure how many users would even notice the change.
Ah, thanks, that looks better. I guess I should clean up that branch and make it actually backwards-compatible. Theming may sound minor, but it looks far better on Windows, for example.
@QuLogic For the default popup window, even the current backend can look modern with just a few tiny tweaks: see #22174.
The one case where Ttk does make a big difference for me was when I'm embedding matplotlib and using themes for the rest of the application (such as ttkbootstrap), which makes the toolbar look rather out of place. In terms of backwards compatibility, I was considering making a separate backend for Ttk, but since most of the backend is private, dropping support for Tk 8.4 (8.5 which brings Ttk was released in 2007...) could make things a lot easier if you want to just switch to Ttk entirely.
Activity
timhoffm commented on Jan 8, 2022
@daniilS you seem knowledgeable in Tk and care for improving it. Do you know if this is possible in Tk?
daniilS commented on Jan 8, 2022
@timhoffm not that straightforward in pure Tk, but since we're already using Pillow it's very easy. Did you set the background colour for the buttons manually, or is there some function that sets it? So I know where to check for the button background colour.
timhoffm commented on Jan 8, 2022
The icon background is transparent, so it effectively uses the theme background. We color the icon with the window text color. Relying on the theme colors will give a reasonable contrast and consistent look. See
matplotlib/lib/matplotlib/backends/backend_qt.py
Line 695 in bf3c651
and
matplotlib/lib/matplotlib/backends/backend_wx.py
Line 1127 in bf3c651
daniilS commented on Jan 8, 2022
@timhoffm Ah, I get what you're asking. Tk doesn't have a proper application-wide theme without using Ttk (that reminds me, I've been meaning to write a _backend_ttk when I have a few free days...), but I wrote up a quick fix in #22163 that checks the background colour of the button, and changes the icon colour to the button's text colour if the background's HSV Value is under 50%.
I've tested it briefly and it seems to work, but I don't have any realistic use-cases to test it with because in my app I've monkey-patched the backend to use ttk. Could you test it with any real-life cases you're aware of?
Also, question: is there a reason for limiting this to just dark themes?
timhoffm commented on Jan 9, 2022
This was discovered and fixed for the specific case: "Our icons are hardly visible in dark themes, let's make them light there" #14810. This is the minimal workaround to fix the default icons and reduce the likelihood of messing up user icons. Let's move further discussion to #22164.
QuLogic commented on Jan 11, 2022
I have attempted this before, but the toggle buttons don't look great, as Ttk doesn't support turning off the check box.
Here is a backwards-incompatible start at it: QuLogic@3ec45d8 (pulled out of my stashes, which conflicted and maybe I didn't fix properly)
daniilS commented on Jan 11, 2022
@QuLogic a toggle button can be created easily by using ttk.Checkbutton(..., style="Toolbutton"). The main reason I was considering this is because I wanted to write a Tk equivalent of qt_editor, for which I'd be using Ttk, and at that point it would be good to make the toolbar's look consistent with it. The only big difference between a Tk and Ttk toolbar would be how they respond to user themes though, so I'm not sure how many users would even notice the change.
QuLogic commented on Jan 11, 2022
Ah, thanks, that looks better. I guess I should clean up that branch and make it actually backwards-compatible. Theming may sound minor, but it looks far better on Windows, for example.
daniilS commented on Jan 11, 2022
@QuLogic For the default popup window, even the current backend can look modern with just a few tiny tweaks: see #22174.
The one case where Ttk does make a big difference for me was when I'm embedding matplotlib and using themes for the rest of the application (such as ttkbootstrap), which makes the toolbar look rather out of place. In terms of backwards compatibility, I was considering making a separate backend for Ttk, but since most of the backend is private, dropping support for Tk 8.4 (8.5 which brings Ttk was released in 2007...) could make things a lot easier if you want to just switch to Ttk entirely.