I am have a problem in the process of my GUI. I have 3 window which is the main window -> 2nd window -> 3rd window then exit. It works well when clicking the button going to 2nd window, but if I clicked the button to window 3 it crushes.
The whole process crushes without saying any error.
This is my Code for the first window:
from window2 import *
from window3 import *
class Ui_MainWindow(object):
def openWindow2(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow2()
self.ui.setupUi2(self.window)
MainWindow.hide()
self.window.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(637, 309)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(230, 90, 341, 16))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(520, 230, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.openWindow2)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
This is the code for the 2nd window:
from window3 import *
class Ui_MainWindow2(object):
def openWindow3(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow3()
self.ui.setupUi3(self.window)
MainWindow.hide()
self.window.show()
def setupUi2(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(481, 242)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(340, 180, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.openWindow3)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(210, 100, 61, 16))
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow2()
ui.setupUi2(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
This is the code for the 3rd window:
from window1 import *
from window2 import *
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow3(object):
def setupUi3(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(397, 319)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(180, 110, 47, 13))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(290, 250, 75, 23))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow3()
ui.setupUi3(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Can someone tell me why the process crushes in the 2nd window when button clicked and why it cannot proceed to the 3rd window?
Try it:
window1.py
window2.py
window3.py
Update
window1.py
window2.py
window3.py