import sys
import typing
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(318, 483)
MainWindow.setStyleSheet("QWidget {\n"
" background-color: #5bbfde;\n"
"}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 7, 0, 1, 1)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setStyleSheet("background-color: rgb(255, 255, 255);")
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(Window2.btn)
self.gridLayout.addWidget(self.pushButton, 8, 0, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(36)
font.setBold(True)
self.label.setFont(font)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1, QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setStyleSheet("background-color: rgb(255, 255, 255);")
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout.addWidget(self.pushButton_3, 6, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setMaximumSize(QtCore.QSize(1000, 1000))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(True)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 4, 0, 1, 1, QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "FirstGuiApp"))
self.pushButton_2.setText(_translate("MainWindow", "Средне"))
self.pushButton.setText(_translate("MainWindow", "Легко"))
self.label.setText(_translate("MainWindow", "ВИКТОРИНА"))
self.pushButton_3.setText(_translate("MainWindow", "Сложно"))
self.label_2.setText(_translate("MainWindow", "Выберите уроовень сложности:"))
class Window2(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Window2, self).__init__()
self.setWindowTitle('Window2')
def btn(self):
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w2 = QtWidgets.QMdiSubWindow()
w2.show()
app.exec_()
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_())
сама ошибка в функции btn, не могу сделать так, чтобы при нажатии на кнопку основное окно закрывалось, а новое открывалось;
по итогу в терминале я получаю вот это: qcoreapplication::exec: the event loop is already running