File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -652,6 +652,17 @@ def _set_image_for_button(self, button):
652
652
# Use the high-resolution (48x48 px) icon if it exists and is needed
653
653
with Image .open (path_large if (size > 24 and path_large .exists ())
654
654
else path_regular ) as im :
655
+ # (r, g, b) tuple in the range from 0 to 65535
656
+ background_rgb = button .winfo_rgb (button .cget ("background" ))
657
+ if max (background_rgb ) < 65535 / 2 :
658
+ # change the colour of the icon to be visible against
659
+ # the dark background
660
+ foreground = (255 / 65535 ) * np .array (
661
+ button .winfo_rgb (button .cget ("foreground" )))
662
+ image_data = np .asarray (im )
663
+ black_mask = (image_data [..., :3 ] == 0 ).all (axis = - 1 )
664
+ image_data [black_mask , :3 ] = foreground
665
+ im = Image .fromarray (image_data , mode = "RGBA" )
655
666
image = ImageTk .PhotoImage (im .resize ((size , size )), master = self )
656
667
button .configure (image = image , height = '18p' , width = '18p' )
657
668
button ._ntimage = image # Prevent garbage collection.
You can’t perform that action at this time.
0 commit comments