8000 Change colour of Tk toolbar icons on dark backgrounds · matplotlib/matplotlib@1e4f9e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e4f9e1

Browse files
committed
Change colour of Tk toolbar icons on dark backgrounds
1 parent 5de27aa commit 1e4f9e1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,17 @@ def _set_image_for_button(self, button):
652652
# Use the high-resolution (48x48 px) icon if it exists and is needed
653653
with Image.open(path_large if (size > 24 and path_large.exists())
654654
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")
655666
image = ImageTk.PhotoImage(im.resize((size, size)), master=self)
656667
button.configure(image=image, height='18p', width='18p')
657668
button._ntimage = image # Prevent garbage collection.

0 commit comments

Comments
 (0)
0