Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Description
Bug summary
Using matplotlib backend for a navigation toolbar in tkinter withgrid
package manager gives the error:
_tkinter.TclError: cannot use geometry manager pack inside .!frame which already has slaves managed by grid
One should be able to use either package managerspack
orgrid
ideally.
Code for reproduction
importtkinterimporttkinterastkfrommpl_toolkits.mplot3dimportAxes3Dfrommpl_toolkits.mplot3dimportproj3dfrommatplotlib.backends.backend_tkaggimport (FigureCanvasTkAgg,NavigationToolbar2Tk)window=tkinter.Tk()window.wm_title("MRI in Tk")frame=ttk.Frame(window)frame.grid(row=0,column=0,sticky="nsew")fig=Figure(figsize=(8,8))pc_label=FigureCanvasTkAgg(fig,master=frame)pc_label.get_tk_widget().grid(row=0,column=1)pc_toolbar_label=NavigationToolbar2Tk(pc_label,frame)pc_toolbar_label.grid(row=0,column=1,sticky="s")
Actual outcome
Traceback (most recent call last): File "/home/varora/PythonProjects/gui/tmp.py", line 16, in <module> pc_toolbar_label = NavigationToolbar2Tk(pc_label, frame) File "/home/varora/anaconda3/envs/nnunet_venv/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 657, in __init__ self.pack(side=tk.BOTTOM, fill=tk.X) File "/home/varora/anaconda3/envs/nnunet_venv/lib/python3.10/tkinter/__init__.py", line 2425, in pack_configure self.tk.call(_tkinter.TclError: cannot use geometry manager pack inside .!frame which already has slaves managed by grid
Expected outcome
Additional information
This script uses amatplotlib
backend fortkinter
for displaying the navigation toolbar which natively implements
the package managerpack()
fortkinter
. Since we usegrid()
package manager, this creates a conflict and hence
you need to change theLine: 657
in[PYTHON-DIR]/site-packages/matplotlib/backends/_backend_tk.py
.
One should be able to use either package managers ideally.
Operating system
Ubuntu
Matplotlib Version
3.7.2
Matplotlib Backend
module://backend_interagg
Python version
3.10
Jupyter version
No response
Installation
pip