Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cc9172

Browse files
committed
Add potential fix for X11 using a special selectcolor
1 parent c4c7152 commit 3cc9172

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,14 @@ def _set_image_for_button(self, button):
651651
size = button.winfo_pixels('18p')
652652

653653
# Nested functions because ToolbarTk calls _Button.
654-
def _is_dark(color):
654+
def _get_color(color_name):
655655
# `winfo_rgb` returns an (r, g, b) tuple in the range 0-65535
656-
return max(button.winfo_rgb(button.cget(color))) < 65535 / 2
656+
return button.winfo_rgb(button.cget(color_name))
657+
658+
def _is_dark(color):
659+
if isinstance(color, str):
660+
color = _get_color(color)
661+
return max(color) < 65535 / 2
657662

658663
def _recolor_icon(image, color):
659664
image_data = np.asarray(image).copy()
@@ -683,7 +688,15 @@ def _recolor_icon(image, color):
683688
isinstance(button, tk.Checkbutton)
684689
and button.cget("selectcolor") != ""
685690
):
686-
if _is_dark("selectcolor"):
691+
if self._windowingsystem != "x11":
692+
selectcolor = "selectcolor"
693+
else:
694+
# On X11, selectcolor isn't used directly for indicator-less
695+
# buttons.
696+
r1, g1, b1 = _get_color("selectcolor")
697+
r2, g2, b2 = _get_color("activebackground")
698+
selectcolor = ((r1+r2)/2, (g1+g2)/2, (b1+b2)/2)
699+
if _is_dark(selectcolor):
687700
button.configure(selectimage=image_alt)
688701
else:
689702
button.configure(selectimage=image)

0 commit comments

Comments
 (0)