Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change colour of Tk toolbar icons on dark backgrounds#22163

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 1 commit intomatplotlib:mainfromdaniilS:tk_toolbar_colours
Mar 26, 2022

Conversation

daniilS
Copy link
Contributor

PR Summary

Closes#22150

Threshold taken from

ifself.palette().color(self.backgroundRole()).value()<128:
Icon colouring taken from
black_mask= (image[..., :3]==0).all(axis=-1)

@daniilS
Copy link
ContributorAuthor

The icons now check the colours for all possible states of the button, and I've added a unit test to keep codecov happy.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, this looks good.

The only issue is still with toggle buttons which have a light-grey icon on a white background:
grafik

@daniilS
Copy link
ContributorAuthor

daniilS commentedJan 9, 2022
edited
Loading

The Tkcheckbutton does allow setting a different image for the selected state using-selectimage, but I don't think it supports different text colours for the selected state, so I assumed whatever is set as the text colour must work for both states. Should I just default to the black icon ifselectcolor isn't dark then?

Also, can I ask if you're using any library to set the colours in your example, or are you setting them yourself?

@timhoffm
Copy link
Member

timhoffm commentedJan 9, 2022
edited
Loading

Should I just default to the black icon if selectcolor isn't dark then?

Yes.

Also, can I ask if you're using any library to set the colours in your example, or are you setting them yourself?

You mean the sceenshot?

That's just the standard KDE "breeze dark" theme.

@daniilS
Copy link
ContributorAuthor

Yes.

Alright, that should be easy to do. Will update soon.

That's just the standard KDE "breeze dark" theme.

Ah, I've never used KDE myself so not familiar with how Tk reads its theme files. Out of interest, how does a regulartk.Checkbutton(master, indicatoron=False, text="sometext") look in the default and selected states? If it does somehow set a different foreground colour for the selected state, it should be possible to retrieve and apply that to the icon.

@timhoffm
Copy link
Member

You mean from:

import tkinter as tk app = tk.Tk() app.geometry('150x100')bt1 = tk.Checkbutton(app, text='Check Box', indicatoron=False) bt1.grid(column=0, row=0)bt2 = tk.Checkbutton(app, text='Check Box', indicatoron=False) bt2.grid(column=0, row=1)app.mainloop()

grafik

Seems it doesn't play well with the theme either.

@daniilS
Copy link
ContributorAuthor

daniilS commentedJan 10, 2022
edited
Loading

That's exactly what I meant, thanks! In that case since the theme doesn't change the foreground colour for theselected state, it should be okay to just use the default icon colour if the background is light.

timhoffm reacted with thumbs up emoji

@daniilS
Copy link
ContributorAuthor

daniilS commentedJan 11, 2022
edited
Loading

@timhoffm this should now cover all relevant cases, could you confirm that it also works with your themes please? Should also be more readable, at the cost of storing both images even when not needed.

@daniilS
Copy link
ContributorAuthor

Of course,ToolbarTk calls_Button with itself as an argument, so all new functions either have to be nested or called explicitly from the class...

Test should hopefully be fixed now.

@timhoffm
Copy link
Member

@daniilS there's a difference in the selected buttons depending on mouse hover. To keep it simple I'd use the same image for hovered and unhovered. It's important that both are readable. It's not so important to indicate the hover state.

Unselected:
grafik

Selected with mouse hover:
grafik

Selected without mouse hover:
grafik

@daniilS
Copy link
ContributorAuthor

@timhoffm Tk lets you specify the background colour for the hover state, but only differentiates between images depending on whether the button is selected or not, so the same image is already being used.

I think the actual issue might be that on X11, Tk has somespecial logic for the selected state, rather than usingselectcolor directly. Could you try the latest commit to see if that fixes it? (On Windows, I can't reproduce your screenshots: )
Unselected:
unselected
Unselected, hover/click:
unselected-active
Selected:
selected
Selected, hover/click:
selected-active

@timhoffm
Copy link
Member

Unselected:
grafik

Unselected, hover/click:
grafik

Selected:
grafik

Selected, hover/click:
grafik

There's now hover-change for unselected, but that's ok by me. It's all readable.

@daniilS
Copy link
ContributorAuthor

daniilS commentedJan 19, 2022
edited
Loading

The background colour of the hover state is set by the theme, not this PR. Looks like the colours of the icons are now working on X11 too then. I've squashed the commit with the X11 fix, so this is ready for review/merge now.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Modulo adding a comment for clarification.

@tacaswelltacaswell added this to thev3.6.0 milestoneMar 23, 2022
@tacaswelltacaswellforce-pushed thetk_toolbar_colours branch 2 times, most recently fromde2005b toff60b28CompareMarch 23, 2022 23:03
@tacaswell
Copy link
Member

Rebased and updated for the new test test scheme (twice).

Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@daniilS
Copy link
ContributorAuthor

Thanks@tacaswell, anything else I need to do on this or good to go now?

@tacaswell
Copy link
Member

@daniilS If you could confirm that I did not break this while rebasing I'll go ahead and merge it!

@daniilS
Copy link
ContributorAuthor

@tacaswell all working so should be good to merge!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@QuLogicQuLogicQuLogic left review comments

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

[ENH]: Tool icons are hardly visible in Tk when using a dark theme
6 participants
@daniilS@timhoffm@tacaswell@QuLogic@dstansby@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp