Crash closing app after using matplotlib
<p>I'm getting a messy crash trying to close my python tkinter app (on ubuntu) after I have shown and closed a matplotlib plot. I am just closing the window using the 'x'.</p>

<pre><code>invalid command name "140146113720200poll"
while executing
</code></pre>

<p>"140146113720200poll"
    ("after" script)</p>

<p>I clearly haven't closed something down properly, I found a couple of places saying a should close the figure on windows close, but figure has no close method. What should I do to properly release the resources I am using?</p>

<pre><code>def plotit(self):
    if self.gdata is None:
        return

    if self.plotframe is None:
        self.plotframe = tkinter.Toplevel()
        self.plotframe.title('graphy stuff')

    self.plotfig = matplotlib.pyplot.figure()
    canvas = FigureCanvasTkAgg(self.plotfig, master=self.plotframe)
    ax = Axes3D(self.plotfig)
    ax.scatter(self.gdata[0],self.gdata[1],self.gdata[2],marker='o',s=1.3)

    canvas.show()
    canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)

    toolbar = NavigationToolbar2TkAgg(canvas, self.plotframe)
    toolbar.update()
    canvas._tkcanvas.pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
</code></pre>

<p>I tried setting up a tkinter close action on the window, but that doesn't help either.</p>