@@ -651,9 +651,14 @@ def _set_image_for_button(self, button):
651
651
size = button .winfo_pixels ('18p' )
652
652
653
653
# Nested functions because ToolbarTk calls _Button.
654
- def _is_dark ( color ):
654
+ def _get_color ( color_name ):
655
655
# `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
657
662
658
663
def _recolor_icon (image , color ):
659
664
image_data = np .asarray (image ).copy ()
@@ -683,7 +688,15 @@ def _recolor_icon(image, color):
683
688
isinstance (button , tk .Checkbutton )
684
689
and button .cget ("selectcolor" ) != ""
685
690
):
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 ):
687
700
button .configure (selectimage = image_alt )
688
701
else :
689
702
button .configure (selectimage = image )
0 commit comments