From 611598894b39830685234bbc230a47beb9625133 Mon Sep 17 00:00:00 2001 From: daniilS Date: Wed, 13 Apr 2022 15:09:24 +0100 Subject: [PATCH] Fix Tk error when updating Checkbutton images --- lib/matplotlib/backends/_backend_tk.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 67f8d792d996..c759fe4840d6 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -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. @@ -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: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy