title: How to uncheck a checkbox after the close_event of figure in Python
body: <p>This is my first question, so please let me know if I make any faux pas.</p>
  
  <p>I'd like to have a check-box that creates and destroys a plot. If that plot is closed using the window's "x", then I'd like the check-box to be unchecked.</p>
  
  <p>I've got it all working except the unchecking upon figure closing.</p>
  
  <p>It looks like my close function is getting called, but it crashes when I try to manipulate the check-box.</p>
  
  <pre><code>from tkFont import *
  from Tkinter import *
  import matplotlib.pyplot as plt
  import numpy as np
  
  class Application(Frame):
  
      def velocity_cb(self):
          if self.velocity_var.get()==1:
              print "selected Velocity checkbox"
              x = np.arange(100.)
              self.figureHandles[1] = plt.figure("Velocity")
              # set the close event to run my function
              self.figureHandles[1].canvas.mpl_connect('close_event', self.handle_close)
              plt.plot(x,x)
              plt.show()
          else:
              print "deselected"
              plt.close(self.figureHandles[1])
  
      def handle_close(self,event):
          #print self.ground_var.get()
          print "X'd velocity window"
          #print self.figureHandles[1]
  
          #plt.close(self.figureHandles[1])
          self.velocity_var.set(0)   
  
      def createWidgets(self):
          self.figureHandles = [0]*13
          self.velocity_var = IntVar()
          self.velocity = Checkbutton(self, text="Velocity", variable=self.velocity_var, command=self.velocity_cb)
          self.velocity.grid(row=6,column=0,sticky='W')
          self.velocity.var = self.velocity_var
  
      def __init__(self,master=None):
          Frame.__init__(self,master)
          self.pack()
          self.createWidgets()            
  
  if __name__=='__main__':
      root = Tk() 
      app = Application(master = root)
      app.mainloop()
  </code></pre>