title: How to call multiple Dialogs in PyQt?
body: <p>I have a main dialog and on that dialog there is a button. When the button is clicked, I want to open an another dialog. </p>
  
  <p>Main Dialog code (Function which is called when the button is clicked in the main dialog):</p>
  
  <pre><code>def add_host(self):
          x=add_host.Ui_Dialog1()
          x.main()
  </code></pre>
  
  <p>default function:</p>
  
  <pre><code>if __name__ == "__main__":
      import sys
      global app
      app = QtGui.QApplication(sys.argv)
      Dialog = QtGui.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Secondary dialog (add_host.py) code snapshot:</p>
  
  <pre><code>def main(self):
          app1 = QtGui.QApplication(sys.argv)
          Dialog1 = QtGui.QDialog()
          ui1 = Ui_Dialog1()
          ui1.setupUi1(Dialog1)
          Dialog1.show()
          sys.exit(app.exec_())
  </code></pre>
  
  <p>So when I run the code, it opens the secondary dialog but when I close it, it just freezes, and I get this error message:</p>
  
  <pre><code> File "testbot.py", line 175, in add_host
      x.main()
    File "/home/ppp/ppp/add_host.py", line 74, in main
      sys.exit(app.exec_())
  NameError: global name 'app' is not defined
  </code></pre>
  
  <p>Which does make sense, but I have no idea how to resolve it. I try several combinations without success, including adding and deleting <code>app.exec_()</code>.</p>