-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
Bug summary
Cannot save figure when using mpl.rcParams["toolbar"] = "toolmanager"
.
Attempting to save the figure by pressing Ctrl+S
or by clicking the save
button shows the error, and does not open the save window.
Code for reproduction
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams["toolbar"] = "toolmanager"
plt.subplots(1, 1)
plt.show()
Actual outcome
E:\bug.py:4: UserWarning: Treat the new Tool classes introduced in v1.5 as experimental for now; the API and rcParam may change in future versions.
mpl.rcParams["toolbar"] = "toolmanager"
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backends\_backend_tk.py", line 1002, in <lambda>
lambda: self._button_click(name))
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backends\_backend_tk.py", line 1023, in _button_click
self.trigger_tool(name)
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backend_bases.py", line 3308, in trigger_tool
self.toolmanager.trigger_tool(name, sender=self)
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backend_managers.py", line 340, in trigger_tool
tool.trigger(sender, canvasevent, data) # Actually trigger Tool.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backends\_backend_tk.py", line 1046, in trigger
NavigationToolbar2Tk.save_figure(
File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\matplotlib\backends\_backend_tk.py", line 849, in save_figure
filetype_variable = tk.StringVar(self, default_filetype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\tkinter\__init__.py", line 562, in __init__
Variable.__init__(self, master, value, name)
File "C:\Python311\Lib\tkinter\__init__.py", line 394, in __init__
self._root = master._root()
^^^^^^^^^^^^
AttributeError: 'types.SimpleNamespace' object has no attribute '_root'
Expected outcome
A save dialog window with the default file type as .png
.
Additional information
Replacing self
with None
from the line below did suppress the error, but did not set the default file type.
filetype_variable = tk.StringVar(self, default_filetype) |
Operating system
Windows 10
Matplotlib Version
3.8.3
Matplotlib Backend
TkAgg
Python version
Python 3.11.4
Jupyter version
No response
Installation
pip