Skip to content

[Bug]: TclError raised by _set_image_for_button() when _update_window_dpi() runs #22836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
richardsheridan opened this issue Apr 13, 2022 · 1 comment · Fixed by #22841
Closed

Comments

@richardsheridan
Copy link
Contributor

richardsheridan commented Apr 13, 2022

Bug summary

I was trying to debug #22822 and an unrelated error pops up in _set_image_for_button when moving a window between monitors of different DPIs. It is a Tcl error that pops up during the _update_window_dpi callback and is therefore printed without ending the program.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('tkagg')

fig, ax = plt.subplots(1,1)
plt.show()

Actual outcome

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\richa\miniconda3\envs\mpl-dev\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "c:\users\richa\documents\github\matplotlib\lib\matplotlib\backends\_backend_tk.py", line 438, in _update_window_dpi
    self.toolbar._rescale()
  File "c:\users\richa\documents\github\matplotlib\lib\matplotlib\backends\_backend_tk.py", line 574, in _rescale
    NavigationToolbar2Tk._set_image_for_button(self, widget)
  File "c:\users\richa\documents\github\matplotlib\lib\matplotlib\backends\_backend_tk.py", line 674, in _set_image_for_button
    button.configure(image=image)
  File "C:\Users\richa\miniconda3\envs\mpl-dev\lib\tkinter\__init__.py", line 1675, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Users\richa\miniconda3\envs\mpl-dev\lib\tkinter\__init__.py", line 1665, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage10" doesn't exist

Also because the callback is interrupted, some widgets are not rescaled.

Expected outcome

no traceback and properly scaled widgets

Additional information

This code was introduced in #22163 to improve the Tk toolbar buttons in dark mode situations. I don't immediately see the cause, but it seems very easy for me to trigger so I'm surprised nobody noticed? attn: @daniilS

Operating system

Windows

Matplotlib Version

main back to ff60b28 (bisected)

Matplotlib Backend

tkagg

Python version

3.10.4

Jupyter version

No response

Installation

git checkout

@daniilS
Copy link
Contributor

daniilS commented Apr 13, 2022

Thanks for spotting this! I think it's because for a checkbutton, changing the image option also re-initialises selectimage. However, when creating the new images, we overwrite the reference to the previously used selectimage, so it's already been garbage collected. Setting image and selectimage at the same time should fix it, see #22841.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants