Reputation: 947
I'm trying to run some code from the console, but am getting the TclError. Below is the entire traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "SM_analyser.py", line 446, in OnB_maxq
self.canvas = FigureCanvasTkAgg(self.plotter, self)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 225, in __init__
master=master, width=w, height=h, borderwidth=4)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2195, in __init__
Widget.__init__(self, master, 'canvas', cnf, kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2055, in __init__
(widgetName, self._w) + extra + self._options(cnf))
TclError: can't invoke "canvas" command: application has been destroyed
I'm reasonably sure the the following block of code is responsible. It should be adding the plot 'figure' to a tkinter canvas, but when I run it 'figure' is plotted in a separate window and the Tcl error is given.
self.plotter = plt.figure('figure')
plt.contour(array, linewidths = 1, colors = 'k')
plt.contourf(array, cmap = plt.cm.jet)
plt.ylabel('Y', fontdict = {'fontsize':16})
plt.xlabel('A', fontdict = {'fontsize':16})
plt.colorbar()
plt.title('figure', fontdict = {'fontsize':20})
plt.show()
self.canvas = FigureCanvasTkAgg(self.plotter, self)
self.canvas.get_tk_widget().grid(column=14,row=2,rowspan=34)
plt.close()
self.canvas._tkcanvas.config(highlightthickness=0)
Upvotes: 1
Views: 5330
Reputation: 385960
TclError: can't invoke "canvas" command: application has been destroyed
means that you are trying to create an instance of a Canvas
class, but that the main window of the application no longer exists. You might want to step through the logic of your program to see if you're destroying the root window at some point prior to creating the canvas.
Upvotes: 1