У меня не получается реализовать открытие ещё одного экрана по нажатию кнопки. При нажатии кнопки вылетает Process finished with exit code 1073741845. Если я пытаюсь заменить exec на 28 строке на show, то окно лишь вылетает на мгновение. Заранее благодарен.
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from project_pyqt_des import Ui_MainWindow
from task_4 import Ui_MainWindow4
class FirstTask(QMainWindow, Ui_MainWindow4):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setWindowTitle('Задание №4')
class Application(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setWindowTitle(
'Тренажёр для подготовки к ЕГЭ по русскому языку')
self.task_4.clicked.connect(self.first_task)
def first_task(self):
window_4 = FirstTask()
window_4.exec()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Application()
ex.show()
sys.exit(app.exec())
Вот дизайн основного окна
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(816, 460)
MainWindow.setMinimumSize(QtCore.QSize(816, 460))
MainWindow.setMaximumSize(QtCore.QSize(816, 460))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 801, 441))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.task_4 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_4.setFont(font)
self.task_4.setObjectName("task_4")
self.verticalLayout.addWidget(self.task_4)
self.task_7 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_7.setFont(font)
self.task_7.setObjectName("task_7")
self.verticalLayout.addWidget(self.task_7)
self.task_9 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_9.setFont(font)
self.task_9.setObjectName("task_9")
self.verticalLayout.addWidget(self.task_9)
self.horizontalLayout.addLayout(self.verticalLayout)
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.task_10 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_10.setFont(font)
self.task_10.setObjectName("task_10")
self.verticalLayout_2.addWidget(self.task_10)
self.task_11 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_11.setFont(font)
self.task_11.setObjectName("task_11")
self.verticalLayout_2.addWidget(self.task_11)
self.task_12 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_12.setFont(font)
self.task_12.setObjectName("task_12")
self.verticalLayout_2.addWidget(self.task_12)
self.horizontalLayout.addLayout(self.verticalLayout_2)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.task_13 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_13.setFont(font)
self.task_13.setObjectName("task_13")
self.verticalLayout_3.addWidget(self.task_13)
self.task_14 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_14.setFont(font)
self.task_14.setObjectName("task_14")
self.verticalLayout_3.addWidget(self.task_14)
self.task_15 = QtWidgets.QPushButton(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(18)
self.task_15.setFont(font)
self.task_15.setObjectName("task_15")
self.verticalLayout_3.addWidget(self.task_15)
self.horizontalLayout.addLayout(self.verticalLayout_3)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 1)
self.title_label = QtWidgets.QLabel(self.gridLayoutWidget)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(26)
self.title_label.setFont(font)
self.title_label.setObjectName("title_label")
self.gridLayout.addWidget(self.title_label, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.task_4.setText(_translate("MainWindow", "Задание №4"))
self.task_7.setText(_translate("MainWindow", "Задание №7"))
self.task_9.setText(_translate("MainWindow", "Задание №9"))
self.task_10.setText(_translate("MainWindow", "Задание №10"))
self.task_11.setText(_translate("MainWindow", "Задание №11"))
self.task_12.setText(_translate("MainWindow", "Задание №12"))
self.task_13.setText(_translate("MainWindow", "Задание №13"))
self.task_14.setText(_translate("MainWindow", "Задание №14"))
self.task_15.setText(_translate("MainWindow", "Задание №15"))
self.title_label.setText(_translate("MainWindow", "Тренажёр для подготовки к ЕГЭ по русскому языку"))
Вот дизайн окна, вызываемого кнопкой "Задание №4"
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow4(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.task_label = QtWidgets.QLabel(self.centralwidget)
self.task_label.setGeometry(QtCore.QRect(0, 10, 801, 91))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(22)
self.task_label.setFont(font)
self.task_label.setObjectName("task_label")
self.label_14 = QtWidgets.QLabel(self.centralwidget)
self.label_14.setGeometry(QtCore.QRect(100, 130, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.label_14.setFont(font)
self.label_14.setObjectName("label_14")
self.label_24 = QtWidgets.QLabel(self.centralwidget)
self.label_24.setGeometry(QtCore.QRect(100, 170, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.label_24.setFont(font)
self.label_24.setObjectName("label_24")
self.label_34 = QtWidgets.QLabel(self.centralwidget)
self.label_34.setGeometry(QtCore.QRect(100, 210, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.label_34.setFont(font)
self.label_34.setObjectName("label_34")
self.label_44 = QtWidgets.QLabel(self.centralwidget)
self.label_44.setGeometry(QtCore.QRect(100, 250, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.label_44.setFont(font)
self.label_44.setObjectName("label_44")
self.label_54 = QtWidgets.QLabel(self.centralwidget)
self.label_54.setGeometry(QtCore.QRect(100, 290, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.label_54.setFont(font)
self.label_54.setObjectName("label_54")
self.out_label = QtWidgets.QLabel(self.centralwidget)
self.out_label.setGeometry(QtCore.QRect(20, 340, 91, 31))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(20)
self.out_label.setFont(font)
self.out_label.setObjectName("out_label")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(110, 330, 651, 41))
self.textBrowser.setObjectName("textBrowser")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(
_translate("MainWindow", "MainWindow"))
self.task_label.setText(_translate("MainWindow",
"В одном из приведённых ниже слов допущена ошибка в \n"
"постановке ударения: НЕВЕРНО выделена буква, \n"
"обозначающая ударный гласный звук. Выпишите это слово."))
self.label_14.setText(_translate("MainWindow", "1 слово"))
self.label_24.setText(_translate("MainWindow", "2 слово"))
self.label_34.setText(_translate("MainWindow", "3 слово"))
self.label_44.setText(_translate("MainWindow", "4 слово"))
self.label_54.setText(_translate("MainWindow", "5 слово"))
self.out_label.setText(_translate("MainWindow", "Ответ:"))
self.textBrowser.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))