title: How to correct the "exception in Tkinter callback" error in python?
body: <p>Here is my code:</p>
  
  <pre><code>#Game Restart Func 
  
  def restart_program():
      for widget in root.winfo_children():
          widget.destroy()
  
      button = Button(root, text='Stop', width=25, command=root.destroy)
      button.pack()
  
      b1 = Button(root, text="Restart", command=restart_program)
      b1.pack()
  
      g = GalagaGame(root)
      root.after(10, g.gameLoop())
      root.mainloop()
  </code></pre>
  
  <p>This function is a function to restart the game
  And the main function was written like this</p>
  
  <pre><code>root = Tk()
  
  button = Button(root, text='Stop', width=25, command=root.destroy)
  button.pack()
  
  b1 = Button(root, text="Restart", command=restart_program)
  b1.pack()
  
  g = GalagaGame(root)
  root.after(10, g.gameLoop())
  root.mainloop()
  </code></pre>
  
  <p>But there are still strange errors.</p>
  
  <p>Exception in Tkinter callback</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
      return self.func(*args)
  
    File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 745, in callit
      func(*args)
  
    File "C:\Users\Kim Donguk\Desktop\Game project\game_source\game.py", line 281, in gameLoop
      self.paint(self.canvas)
  
    File "C:\Users\Kim Donguk\Desktop\Game project\game_source\game.py", line 260, in paint
      self.canvas.delete(ALL)
  
    File "C:\Users\Kim Donguk\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2508, in delete
      self.tk.call((self._w, 'delete') + args)
  
  _tkinter.TclError: invalid command name ".!canvas"
  </code></pre>
  
  <p>How can I fix this error?</p>