@@ -669,9 +669,13 @@ def _recolor_icon(image, color):
669
669
button ._ntimage_alt = image_alt
670
670
671
671
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 }
673
677
else :
674
- button . configure ( image = image )
678
+ image_kwargs = { " image" : image }
675
679
# Checkbuttons may switch the background to `selectcolor` in the
676
680
# checked state, so check separately which image it needs to use in
677
681
# that state to still ensure enough contrast with the background.
@@ -689,11 +693,11 @@ def _recolor_icon(image, color):
689
693
r2 , g2 , b2 = _get_color ("activebackground" )
690
694
selectcolor = ((r1 + r2 )/ 2 , (g1 + g2 )/ 2 , (b1 + b2 )/ 2 )
691
695
if _is_dark (selectcolor ):
692
- button . configure ( selectimage = image_alt )
696
+ image_kwargs [ " selectimage" ] = image_alt
693
697
else :
694
- button . configure ( selectimage = image )
698
+ image_kwargs [ " selectimage" ] = image
695
699
696
- button .configure (height = '18p' , width = '18p' )
700
+ button .configure (** image_kwargs , height = '18p' , width = '18p' )
697
701
698
702
def _Button (self , text , image_file , toggle , command ):
699
703
if not toggle :
0 commit comments