Here is the working example.
dialog_01.py
import sys, os
from PyQt4 import QtCore, QtGui
class Dialog_01(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
myQWidget = QtGui.QWidget()
myBoxLayout = QtGui.QVBoxLayout()
Cancel_button = QtGui.QPushButton("Cancel")
Cancel_button.clicked.connect(self.Cancel)
myBoxLayout.addWidget(Cancel_button)
Button_01 = QtGui.QPushButton("Press to close this dialog and open Dialog 02")
Button_01.clicked.connect(self.callAnotherQMainWindow)
myBoxLayout.addWidget(Button_01)
myQWidget.setLayout(myBoxLayout)
self.setCentralWidget(myQWidget)
self.setWindowTitle('Dialog 01')
def callAnotherQMainWindow(self):
from dialog_02 import Dialog_02
self.close()
self.dialog_02 = Dialog_02()
self.dialog_02.show()
self.dialog_02.raise_()
def Cancel(self):
self.close()
# def closeEvent(self, event):
# self.deleteLater()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_1 = Dialog_01()
dialog_1.show()
dialog_1.resize(480,320)
sys.exit(app.exec_())
dialog_02.py
import sys, os
from PyQt4 import QtCore, QtGui
class Dialog_02(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
myQWidget = QtGui.QWidget()
myBoxLayout = QtGui.QVBoxLayout()
Cancel_button = QtGui.QPushButton("Cancel")
Cancel_button.clicked.connect(self.Cancel)
myBoxLayout.addWidget(Cancel_button)
Button_02 = QtGui.QPushButton("Press to close this dialog 02 and re-open Dialog 01")
Button_02.clicked.connect(self.callAnotherQMainWindow)
myBoxLayout.addWidget(Button_02)
myQWidget.setLayout(myBoxLayout)
self.setCentralWidget(myQWidget)
self.setWindowTitle('Dialog 02')
def callAnotherQMainWindow(self):
from dialog_01 import Dialog_01
self.close()
self.dialog_01 = Dialog_01()
self.dialog_01.show()
self.dialog_01.raise_()
def Cancel(self):
self.close()
# def closeEvent(self, event):
# self.deleteLater()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_2 = Dialog_02()
dialog_2.show()
dialog_2.resize(480,320)
sys.exit(app.exec_())