title: python Tkinter script written by class acts abnormally, but using function style works fine
body: <p>The script written by class style can't update listbox as expectation
  I expect this code updates listbox content from &quot; &quot; to &quot;2 2 2&quot; after pressing start button</p>
  <p>code floor:
  1.function <em><strong>empty_listbox</strong></em> in class <em><strong>Leftframe</strong></em> generates empty listbox</p>
  <p>2.User press start_btn in <em><strong>Rightframe</strong></em>  (another script start generate a file 'XXX.pkl')</p>
  <p>3.function <em><strong>chk_file_exist</strong></em> in class <em><strong>Rightframe</strong></em> will waits until 'XXX.pkl' exists(I have force this condition be True for debugging)</p>
  <p>4.function <em><strong>chk_file_exist</strong></em> in class <em><strong>Rightframe</strong></em> calls function <em><strong>update_listbox</strong></em> in class <em><strong>Leftframe</strong></em> to update listbox's content, <strong>but fails</strong></p>
  <p>class style script:</p>
  <pre><code>import tkinter as tk
  import os
  
  class Leftframe(tk.Frame):
      def __init__(self, parent, *args, **kwargs):
          tk.Frame.__init__(self, parent, *args, **kwargs)
          self.parent = parent
          self.scrollbar = tk.Scrollbar(self)
          self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
          self.mylist = tk.Listbox(self, yscrollcommand=self.scrollbar.set)
          self.mylist.place(x=0, y=0, width=260, height=410)
          self.scrollbar.config(command=self.mylist.yview)
          self.empty_listbox()
      def empty_listbox(self):
          self.mylist.delete(0, tk.END)
          for it in ([' ']):
              self.mylist.insert(tk.END, it)
      def update_listbox(self):
          self.mylist.delete(0, tk.END)
          for it in (['2','2','2']):
              self.mylist.insert(tk.END, it)
              print('Iamhere, update listbox!')#why
  
  class Rightframe(tk.Frame):
      def __init__(self, parent, *args, **kwargs):
          tk.Frame.__init__(self, parent, *args, **kwargs)
          self.parent = parent
          self.start_btn = tk.Button(self,text='Start')
          self.start_btn.config(command=self.button_start_push)
          self.start_btn.place(anchor=tk.NW,x=10,y=10,width=60,height=20)
          self.stop_btn = tk.Button(self,text='Stop')
          self.stop_btn['state'] = tk.DISABLED
          self.stop_btn.config(command=self.button_stop_push)
          self.stop_btn.place(anchor=tk.NW,x=10,y=60,width=60,height=20)
  
      def chk_file_exist(self):
          if 1:#os.path.isfile(os.path.join(os.curdir, fileroute)): force for debugging!!
              Leftframe(self.parent).update_listbox()###error TypeError: __init__() missing 1 required positional argument: 'parent'
          else:
              print('file generating, please wait')#other script generating file in background
              main_win.after(1000, self.chk_file_exist)
      def button_start_push(self):
          print('Started')
          self.start_btn['state'] = tk.DISABLED
          self.stop_btn['state'] = tk.NORMAL
          global fileroute
          self.chk_file_exist()
  
      def button_stop_push(self):
          print('stop button pressed')
          self.start_btn['state'] = tk.NORMAL
          open(os.path.join(os.curdir, 'stop.txt'), 'a').close()
  
  
  if __name__ == '__main__':
      fileroute = 'XXX.pkl'
      main_win = tk.Tk()
      main_win.geometry(&quot;200x150+0+0&quot;)
      Leftframe(main_win, relief=&quot;sunken&quot;, borderwidth=1).place(x=10, y=10, width=80, height=100)
      Rightframe(main_win, relief=&quot;sunken&quot;, borderwidth=1).place(x=100, y=10, width=80, height=100)
      main_win.mainloop()
  </code></pre>
  <p>Then I tried to rewrite this code only use function, <strong>it can updates listbox correctly</strong></p>
  <p>function style script:</p>
  <pre><code>import tkinter as tk
  import os
  
  #leftframe function
  def empty_listbox(mylist):
      mylist.delete(0, tk.END)
      for it in ([' ']):
          mylist.insert(tk.END, it)
  
  def update_listbox(mylist):
      mylist.delete(0, tk.END)
      for it in (['2', '2', '2']):
          mylist.insert(tk.END, it)
          print('Iamhere, update listbox!')  # why
  
  # rightframe function
  def chk_file_exist(mylist):
      if 1:#os.path.isfile(os.path.join(os.curdir, fileroute)): force for debugging!!
          update_listbox(mylist)###error TypeError: __init__() missing 1 required positional argument: 'parent'
      else:
          print('file generating, please wait')#other script generating file in background
          main_win.after(1000, chk_file_exist)
  def button_start_push():
      print('Started')
      start_btn['state'] = tk.DISABLED
      stop_btn['state'] = tk.NORMAL
      global fileroute
      chk_file_exist(mylist)
  
  def button_stop_push():
      print('stop button pressed')
      start_btn['state'] = tk.NORMAL
      open(os.path.join(os.curdir, 'stop.txt'), 'a').close()
  
  
  if __name__ == '__main__':
      fileroute = 'XXX.pkl'
      main_win = tk.Tk()
      main_win.geometry(&quot;200x150+0+0&quot;)
  
      #leftframe
      leftframe=tk.Frame(main_win, relief=&quot;sunken&quot;, borderwidth=1).place(x=10, y=10, width=80, height=100)
      scrollbar = tk.Scrollbar(leftframe)
      scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
      mylist = tk.Listbox( leftframe,yscrollcommand=scrollbar.set)
      mylist.place(x=0, y=0, width=260, height=410)
      scrollbar.config(command=mylist.yview)
      empty_listbox(mylist)
  
      #rightframe
      rightframe=tk.Frame(main_win, relief=&quot;sunken&quot;, borderwidth=1).place(x=100, y=10, width=80, height=100)
      start_btn = tk.Button(rightframe, text='Start')
      start_btn.config(command=button_start_push)
      start_btn.place(anchor=tk.NW, x=10, y=10, width=60, height=20)
      stop_btn = tk.Button( rightframe,text='Stop')
      stop_btn['state'] = tk.DISABLED
      stop_btn.config(command=button_stop_push)
      stop_btn.place(anchor=tk.NW, x=10, y=60, width=60, height=20)
  
      main_win.mainloop()
  </code></pre>
  <p>Can you find out where I made mistake in class style script?</p>
  <p>And why the GUI layout of these two codes look so differently? I tried to debug in class style script but failed.(the buttons location is different)</p>
  <p>class style script<a href="https://i.stack.imgur.com/Ntoyj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ntoyj.png" alt="class style script" /></a></p>
  <p>function style script<a href="https://i.stack.imgur.com/qcldz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qcldz.png" alt="function style script" /></a></p>
  <p>Many thanks!!</p>