title: Python Tkinter safe to self.quit or sys.exit?
body: <p>In the spirit of decoupling, rather than cramming many widgets into one giant class, I tried splitting them into separate classes.</p>
  
  <p>The problem I ran into is the FileMenu class does not know about root, and so cannot call root.quit or root.destroy. On a whim I tried self.quit, and it works, but I have not seen this used before.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is self.quit a safe way to quit the app?</li>
  <li>Is sys.exit a safe way to quit the app?</li>
  <li>If neither are safe, is there a good way to approach decoupling the design and safely quit without passing root as a parameter everywhere or making it a global?</li>
  </ol>
  
  <p>My example:</p>
  
  <pre><code>import Tkinter as tk
  
  class FileMenu(tk.Menu):
      def __init__ (self, parent):
          tk.Menu.__init__(self, parent, tearoff=False)
          self.add_command(label='Exit', command=self.quit)
  
  class MainMenu(tk.Menu):
      def __init__ (self, parent):
          tk.Menu.__init__(self, parent, tearoff=False)
          self.file_menu = FileMenu(self)
          self.add_cascade(label='File', menu=self.file_menu)
  
  class View:
      def __init__ (self, parent):
          self.frame = tk.Frame(parent)
          self.parent = parent
          self.menu = MainMenu(self.frame)
          self.parent.configure(menu=self.menu)
          self.parent.geometry('200x200')
          self.frame.pack(fill='both', expand=True)
  
  class App:
      def __init__ (self):
          self.root = tk.Tk()
          self.view = View(self.root)
  
      def run (self):
          self.root.title('Window Title')
          self.root.mainloop()
  
  if __name__ == '__main__':
      app = App()
      app.run()
  </code></pre>