title: Tkinter button bind and parent deatroy
body: <p>This is my code :</p>
  
  <pre><code>    print '1'
  from Tkinter import *
  print '2'
  class myApp:
  
      print '3'
      def __init__(self,parent):
          print '4'
  
  ##        self.myparent = parent    line1
          print '11'
  
          self.myContainer1 = Frame(parent)
          print '12'
          self.myContainer1.pack()
          print '13'
  
          self.button1 = Button(self.myContainer1,text="OK",background="green")
          print '14'
          self.button1.pack(side=LEFT)
          print '15'
          self.button1.bind("&lt;Button-1&gt;",self.button1Click)
          print '16'
  
          self.button2 = Button(self.myContainer1,text="Cancel",background="cyan")
          print '17'
          self.button2.pack(side=RIGHT)
          print '18'
          self.button2.bind("&lt;Button-1&gt;",self.button2Click)
          print '19'
  
  
      def button1Click(self,event):
  
              print '5'
  
              if self.button1['background'] == 'green':
                  print '20'
                  self.button1['background'] ='tan'
                  print '21'
  
              else:
  
                  print '22'
  
                  self.button1['background'] = 'yellow'
  
                  print '23'
  
      def button2Click(self,event):
  
              print '6'
  
  ##            self.myparent.destroy()
  
              self.parent.destroy()
  
  print '7'
  root = Tk()
  print '8'
  myapp = myApp(root)
  print '9'
  root.mainloop()
  print '10'
  </code></pre>
  
  <p>Error is :</p>
  
  <pre><code>    &gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  1
  2
  3
  7
  8
  4
  11
  12
  13
  14
  15
  16
  17
  18
  19
  9
  5
  20
  21
  5
  22
  23
  6
  Exception in Tkinter callback
  Traceback (most recent call last):
    File "C:\Python26\lib\lib-tk\Tkinter.py", line 1403, in __call__
      return self.func(*args)
    File "C:\Documents and Settings\he00044.HALEDGEWOOD\Desktop\TkinterExamples\buttonBind.py", line 56, in button2Click
      self.parent.destroy()
  AttributeError: myApp instance has no attribute 'parent'
  10
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>This is when i comment line1</p>
  
  <p>It may be becoz myapp is not finding parent.</p>
  
  <p>But the concept is not clear.</p>
  
  <p>Can anybody explain the concept in detail....</p>