8000 Merge pull request #22841 from daniilS/tk_toolbar_colours_fix · matplotlib/matplotlib@4e20f15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e20f15

Browse files
authored
Merge pull request #22841 from daniilS/tk_toolbar_colours_fix
Fix Tk error when updating toolbar checkbutton images
2 parents c1bf6df + 6115988 commit 4e20f15

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,13 @@ def _recolor_icon(image, color):
669669
button._ntimage_alt = image_alt
670670

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

696-
button.configure(height='18p', width='18p')
700+
button.configure(**image_kwargs, height='18p', width='18p')
697701

698702
def _Button(self, text, image_file, toggle, command):
699703
if not toggle:

0 commit comments

Comments
 (0)
0