Skip to content

[ENH]: Tool icons are hardly visible in Tk when using a dark theme #22150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timhoffm opened this issue Jan 8, 2022 · 9 comments · Fixed by #22163
Closed

[ENH]: Tool icons are hardly visible in Tk when using a dark theme #22150

timhoffm opened this issue Jan 8, 2022 · 9 comments · Fixed by #22163

Comments

@timhoffm
Copy link
Member

timhoffm commented Jan 8, 2022

Problem

The icons are hard-coded to be black and blend into the backgound:

grafik

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
Copy link
Member Author

timhoffm commented Jan 8, 2022

@daniilS you seem knowledgeable in Tk and care for improving it. Do you know if this is possible in Tk?

@daniilS
Copy link
Contributor

daniilS commented 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
Copy link
Member Author

timhoffm commented 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

icon_color = self.palette().color(self.foregroundRole())

and

fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)

@daniilS
Copy link
Contributor

daniilS commented 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
Copy link
Member Author

timhoffm commented Jan 9, 2022

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
Copy link
Member

QuLogic commented Jan 11, 2022

that reminds me, I've been meaning to write a _backend_ttk when I have a few free days...,

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
Copy link
Contributor

daniilS commented 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
Copy link
Member

QuLogic commented 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
Copy link
Contributor

daniilS commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants