PyQt5: open main window and close dialog <p>I have a login dialog and a main window. When I login, "success" must close the login dialog and open the main window. Now when I login, the main window is open, but login dialog does not close. But if I try to close it, but both the dialog and the window close. I want keep the window open, and close the login dialog.</p> <p><em>loginDialogStartup.py</em>:</p> <pre><code>class LoginDialogStartup(Ui_Dialog): def __init__(self, dialog): Ui_Dialog.__init__(self) self.setupUi(dialog) self.loginbtn.clicked.connect(self.doLogin) self.cancelbtn.clicked.connect(self.closeEvent) def closeEvent(self, event): print("Closing") self.destory() def doLogin(self): username = self.usernameinput.text() password = self.passwordinput.text() if validLogin(username, password): self.window = QtWidgets.QMainWindow() MainWindowStartup(self.window) self.window.show() self.loginbtn.clicked.connect(self, Qt.SIGNAL('triggered()'), self.closeEvent) else: self.statuplabel.setText("NO") if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) dialog = QtWidgets.QDialog() prog = LoginDialogStartup(dialog) dialog.show() sys.exit(app.exec_()) </code></pre> <p><em>MainWindowStartup.py</em>:</p> <pre><code>class MainWindowStartup(Ui_MainWindow): def __init__(self, window): Ui_MainWindow.__init__(self) self.setupUi(window) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() prog = MainWindowStartup(window) window.show() app.exec_() </code></pre>