Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,13 @@ def _recolor_icon(image, color):
button._ntimage_alt = image_alt

if _is_dark("background"):
button.configure(image=image_alt)
# For Checkbuttons, we need to set `image` and `selectimage` at
# the same time. Otherwise, when updating the `image` option
# (such as when changing DPI), if the old `selectimage` has
# just been overwritten, Tk will throw an error.
image_kwargs = {"image": image_alt}
else:
button.configure(image=image)
image_kwargs = {"image": image}
# Checkbuttons may switch the background to `selectcolor` in the
# checked state, so check separately which image it needs to use in
# that state to still ensure enough contrast with the background.
Expand All @@ -689,11 +693,11 @@ def _recolor_icon(image, color):
r2, g2, b2 = _get_color("activebackground")
selectcolor = ((r1+r2)/2, (g1+g2)/2, (b1+b2)/2)
if _is_dark(selectcolor):
button.configure(selectimage=image_alt)
image_kwargs["selectimage"] = image_alt
else:
button.configure(selectimage=image)
image_kwargs["selectimage"] = image

button.configure(height='18p', width='18p')
button.configure(**image_kwargs, height='18p', width='18p')

def _Button(self, text, image_file, toggle, command):
if not toggle:
Expand Down