m0_74922185 2022-11-05 09:38 采纳率: 100%
浏览 109
已结题

python的gui界面小程序点击按钮闪退

python让用designer设计gui可视化小程序,往里面填充代码。要求是出十道20以内加减法。我的框架运行没有问题,自己编的函数不知道为什么摁按钮就关窗口,运行不了。但是写了槽函数了,不明白为啥。
用代码块功能插入代码,请勿粘贴截图
import random
from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1027, 867)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.horizontalLayout_12 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_12.setObjectName("horizontalLayout_12")
        self.gridLayout_2 = QtWidgets.QGridLayout()
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setObjectName("groupBox")
        self.textEdit = QtWidgets.QTextEdit(self.groupBox)
        self.textEdit.setGeometry(QtCore.QRect(10, 20, 261, 51))
        self.textEdit.setObjectName("textEdit")
        self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 1)
        self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_2.setObjectName("groupBox_2")
        self.textEdit_2 = QtWidgets.QTextEdit(self.groupBox_2)
        self.textEdit_2.setGeometry(QtCore.QRect(10, 20, 261, 51))
        self.textEdit_2.setObjectName("textEdit_2")
        self.gridLayout_2.addWidget(self.groupBox_2, 0, 1, 1, 1)
        self.horizontalLayout_12.addLayout(self.gridLayout_2)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.dateTimeEdit = QtWidgets.QDateTimeEdit(self.centralwidget)
        self.dateTimeEdit.setObjectName("dateTimeEdit")
        self.verticalLayout.addWidget(self.dateTimeEdit)
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        self.horizontalLayout_12.addLayout(self.verticalLayout)
        self.gridLayout.addLayout(self.horizontalLayout_12, 0, 0, 1, 1)
        self.gridLayout_3 = QtWidgets.QGridLayout()
        self.gridLayout_3.setSizeConstraint(QtWidgets.QLayout.SetMaximumSize)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_3.setObjectName("groupBox_3")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.groupBox_3)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.textEdit_3 = QtWidgets.QTextEdit(self.groupBox_3)
        self.textEdit_3.setObjectName("textEdit_3")
        self.horizontalLayout.addWidget(self.textEdit_3)
        self.label = QtWidgets.QLabel(self.groupBox_3)
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.textEdit_4 = QtWidgets.QTextEdit(self.groupBox_3)
        self.textEdit_4.setObjectName("textEdit_4")
        self.horizontalLayout.addWidget(self.textEdit_4)
        self.horizontalLayout.setStretch(0, 9)
        self.horizontalLayout.setStretch(1, 1)
        self.horizontalLayout.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_3, 0, 0, 1, 1)
        self.groupBox_8 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_8.setObjectName("groupBox_8")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.groupBox_8)
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.textEdit_13 = QtWidgets.QTextEdit(self.groupBox_8)
        self.textEdit_13.setObjectName("textEdit_13")
        self.horizontalLayout_6.addWidget(self.textEdit_13)
        self.label_6 = QtWidgets.QLabel(self.groupBox_8)
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_6.addWidget(self.label_6)
        self.textEdit_14 = QtWidgets.QTextEdit(self.groupBox_8)
        self.textEdit_14.setObjectName("textEdit_14")
        self.horizontalLayout_6.addWidget(self.textEdit_14)
        self.horizontalLayout_6.setStretch(0, 9)
        self.horizontalLayout_6.setStretch(1, 1)
        self.horizontalLayout_6.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_8, 0, 1, 1, 1)
        self.groupBox_4 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_4.setObjectName("groupBox_4")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.groupBox_4)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.textEdit_5 = QtWidgets.QTextEdit(self.groupBox_4)
        self.textEdit_5.setObjectName("textEdit_5")
        self.horizontalLayout_2.addWidget(self.textEdit_5)
        self.label_2 = QtWidgets.QLabel(self.groupBox_4)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.textEdit_6 = QtWidgets.QTextEdit(self.groupBox_4)
        self.textEdit_6.setObjectName("textEdit_6")
        self.horizontalLayout_2.addWidget(self.textEdit_6)
        self.horizontalLayout_2.setStretch(0, 9)
        self.horizontalLayout_2.setStretch(1, 1)
        self.horizontalLayout_2.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_4, 1, 0, 1, 1)
        self.groupBox_9 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_9.setObjectName("groupBox_9")
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.groupBox_9)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.textEdit_15 = QtWidgets.QTextEdit(self.groupBox_9)
        self.textEdit_15.setObjectName("textEdit_15")
        self.horizontalLayout_7.addWidget(self.textEdit_15)
        self.label_7 = QtWidgets.QLabel(self.groupBox_9)
        self.label_7.setObjectName("label_7")
        self.horizontalLayout_7.addWidget(self.label_7)
        self.textEdit_16 = QtWidgets.QTextEdit(self.groupBox_9)
        self.textEdit_16.setObjectName("textEdit_16")
        self.horizontalLayout_7.addWidget(self.textEdit_16)
        self.horizontalLayout_7.setStretch(0, 9)
        self.horizontalLayout_7.setStretch(1, 1)
        self.horizontalLayout_7.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_9, 1, 1, 1, 1)
        self.groupBox_5 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_5.setObjectName("groupBox_5")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox_5)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.textEdit_7 = QtWidgets.QTextEdit(self.groupBox_5)
        self.textEdit_7.setObjectName("textEdit_7")
        self.horizontalLayout_3.addWidget(self.textEdit_7)
        self.label_3 = QtWidgets.QLabel(self.groupBox_5)
        self.label_3.setObjectName("label_3")
        self.horizontalLayout_3.addWidget(self.label_3)
        self.textEdit_8 = QtWidgets.QTextEdit(self.groupBox_5)
        self.textEdit_8.setObjectName("textEdit_8")
        self.horizontalLayout_3.addWidget(self.textEdit_8)
        self.horizontalLayout_3.setStretch(0, 9)
        self.horizontalLayout_3.setStretch(1, 1)
        self.horizontalLayout_3.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_5, 2, 0, 1, 1)
        self.groupBox_10 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_10.setObjectName("groupBox_10")
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.groupBox_10)
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.textEdit_17 = QtWidgets.QTextEdit(self.groupBox_10)
        self.textEdit_17.setObjectName("textEdit_17")
        self.horizontalLayout_8.addWidget(self.textEdit_17)
        self.label_8 = QtWidgets.QLabel(self.groupBox_10)
        self.label_8.setObjectName("label_8")
        self.horizontalLayout_8.addWidget(self.label_8)
        self.textEdit_18 = QtWidgets.QTextEdit(self.groupBox_10)
        self.textEdit_18.setObjectName("textEdit_18")
        self.horizontalLayout_8.addWidget(self.textEdit_18)
        self.horizontalLayout_8.setStretch(0, 9)
        self.horizontalLayout_8.setStretch(1, 1)
        self.horizontalLayout_8.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_10, 2, 1, 1, 1)
        self.groupBox_6 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_6.setObjectName("groupBox_6")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.groupBox_6)
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.textEdit_9 = QtWidgets.QTextEdit(self.groupBox_6)
        self.textEdit_9.setObjectName("textEdit_9")
        self.horizontalLayout_4.addWidget(self.textEdit_9)
        self.label_4 = QtWidgets.QLabel(self.groupBox_6)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_4.addWidget(self.label_4)
        self.textEdit_10 = QtWidgets.QTextEdit(self.groupBox_6)
        self.textEdit_10.setObjectName("textEdit_10")
        self.horizontalLayout_4.addWidget(self.textEdit_10)
        self.horizontalLayout_4.setStretch(0, 9)
        self.horizontalLayout_4.setStretch(1, 1)
        self.horizontalLayout_4.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_6, 3, 0, 1, 1)
        self.groupBox_11 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_11.setObjectName("groupBox_11")
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.groupBox_11)
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.textEdit_19 = QtWidgets.QTextEdit(self.groupBox_11)
        self.textEdit_19.setObjectName("textEdit_19")
        self.horizontalLayout_9.addWidget(self.textEdit_19)
        self.label_9 = QtWidgets.QLabel(self.groupBox_11)
        self.label_9.setObjectName("label_9")
        self.horizontalLayout_9.addWidget(self.label_9)
        self.textEdit_20 = QtWidgets.QTextEdit(self.groupBox_11)
        self.textEdit_20.setObjectName("textEdit_20")
        self.horizontalLayout_9.addWidget(self.textEdit_20)
        self.horizontalLayout_9.setStretch(0, 9)
        self.horizontalLayout_9.setStretch(1, 1)
        self.horizontalLayout_9.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_11, 3, 1, 1, 1)
        self.groupBox_7 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_7.setObjectName("groupBox_7")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.groupBox_7)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.textEdit_11 = QtWidgets.QTextEdit(self.groupBox_7)
        self.textEdit_11.setObjectName("textEdit_11")
        self.horizontalLayout_5.addWidget(self.textEdit_11)
        self.label_5 = QtWidgets.QLabel(self.groupBox_7)
        self.label_5.setObjectName("label_5")
        self.horizontalLayout_5.addWidget(self.label_5)
        self.textEdit_12 = QtWidgets.QTextEdit(self.groupBox_7)
        self.textEdit_12.setObjectName("textEdit_12")
        self.horizontalLayout_5.addWidget(self.textEdit_12)
        self.horizontalLayout_5.setStretch(0, 9)
        self.horizontalLayout_5.setStretch(1, 1)
        self.horizontalLayout_5.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_7, 4, 0, 1, 1)
        self.groupBox_12 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_12.setObjectName("groupBox_12")
        self.horizontalLayout_10 = QtWidgets.QHBoxLayout(self.groupBox_12)
        self.horizontalLayout_10.setObjectName("horizontalLayout_10")
        self.textEdit_21 = QtWidgets.QTextEdit(self.groupBox_12)
        self.textEdit_21.setObjectName("textEdit_21")
        self.horizontalLayout_10.addWidget(self.textEdit_21)
        self.label_10 = QtWidgets.QLabel(self.groupBox_12)
        self.label_10.setObjectName("label_10")
        self.horizontalLayout_10.addWidget(self.label_10)
        self.textEdit_22 = QtWidgets.QTextEdit(self.groupBox_12)
        self.textEdit_22.setObjectName("textEdit_22")
        self.horizontalLayout_10.addWidget(self.textEdit_22)
        self.horizontalLayout_10.setStretch(0, 9)
        self.horizontalLayout_10.setStretch(1, 1)
        self.horizontalLayout_10.setStretch(2, 3)
        self.gridLayout_3.addWidget(self.groupBox_12, 4, 1, 1, 1)
        self.gridLayout_3.setColumnStretch(0, 1)
        self.gridLayout_3.setColumnStretch(1, 1)
        self.gridLayout_3.setRowStretch(0, 1)
        self.gridLayout_3.setRowStretch(1, 1)
        self.gridLayout_3.setRowStretch(2, 1)
        self.gridLayout_3.setRowStretch(3, 1)
        self.gridLayout_3.setRowStretch(4, 1)
        self.gridLayout.addLayout(self.gridLayout_3, 1, 0, 1, 1)
        self.horizontalLayout_11 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_11.setObjectName("horizontalLayout_11")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout_11.addWidget(self.pushButton_2)
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setObjectName("pushButton_3")
        self.horizontalLayout_11.addWidget(self.pushButton_3)
        self.groupBox_13 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_13.setObjectName("groupBox_13")
        self.textEdit_23 = QtWidgets.QTextEdit(self.groupBox_13)
        self.textEdit_23.setGeometry(QtCore.QRect(80, 10, 391, 87))
        self.textEdit_23.setObjectName("textEdit_23")
        self.horizontalLayout_11.addWidget(self.groupBox_13)
        self.horizontalLayout_11.setStretch(0, 1)
        self.horizontalLayout_11.setStretch(1, 1)
        self.horizontalLayout_11.setStretch(2, 2)
        self.gridLayout.addLayout(self.horizontalLayout_11, 2, 0, 1, 1)
        self.gridLayout.setRowStretch(0, 1)
        self.gridLayout.setRowStretch(1, 1)
        self.gridLayout.setRowStretch(2, 2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1027, 26))
        self.menubar.setObjectName("menubar")
        self.menufile = QtWidgets.QMenu(self.menubar)
        self.menufile.setObjectName("menufile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionnew = QtWidgets.QAction(MainWindow)
        self.actionnew.setObjectName("actionnew")
        self.actionnew_text = QtWidgets.QAction(MainWindow)
        self.actionnew_text.setObjectName("actionnew_text")
        self.menufile.addAction(self.actionnew)
        self.menufile.addSeparator()
        self.menufile.addAction(self.actionnew_text)
        self.menubar.addAction(self.menufile.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        self.pushButton.clicked.connect(self.Problem)
        self.pushButton_2.clicked.connect(self.Submit)
        self.pushButton_3.clicked.connect(self.Answer)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.groupBox.setTitle(_translate("MainWindow", "姓名"))
        self.groupBox_2.setTitle(_translate("MainWindow", "学校"))
        self.pushButton.setText(_translate("MainWindow", "随机生成试题"))
        self.groupBox_3.setTitle(_translate("MainWindow", "第一题"))
        self.label.setText(_translate("MainWindow", "="))
        self.groupBox_8.setTitle(_translate("MainWindow", "第六题"))
        self.label_6.setText(_translate("MainWindow", "="))
        self.groupBox_4.setTitle(_translate("MainWindow", "第二题"))
        self.label_2.setText(_translate("MainWindow", "="))
        self.groupBox_9.setTitle(_translate("MainWindow", "第七题"))
        self.label_7.setText(_translate("MainWindow", "="))
        self.groupBox_5.setTitle(_translate("MainWindow", "第三题"))
        self.label_3.setText(_translate("MainWindow", "="))
        self.groupBox_10.setTitle(_translate("MainWindow", "第八题"))
        self.label_8.setText(_translate("MainWindow", "="))
        self.groupBox_6.setTitle(_translate("MainWindow", "第四题"))
        self.label_4.setText(_translate("MainWindow", "="))
        self.groupBox_11.setTitle(_translate("MainWindow", "第九题"))
        self.label_9.setText(_translate("MainWindow", "="))
        self.groupBox_7.setTitle(_translate("MainWindow", "第五题"))
        self.label_5.setText(_translate("MainWindow", "="))
        self.groupBox_12.setTitle(_translate("MainWindow", "第十题"))
        self.label_10.setText(_translate("MainWindow", "="))
        self.pushButton_2.setText(_translate("MainWindow", "提交"))
        self.pushButton_3.setText(_translate("MainWindow", "查看答案"))
        self.groupBox_13.setTitle(_translate("MainWindow", "学生成绩"))
        self.menufile.setTitle(_translate("MainWindow", "file"))
        self.actionnew.setText(_translate("MainWindow", "new person"))
        self.actionnew_text.setText(_translate("MainWindow", "new text"))

    def Problem(self):
        global problem,answer,answerRight
        if self.textEdit.text() == '' or self.textEdit_2.text() == '':
            QtWidgets.QMessageBox.information(self,"警告","未填学校信息和学生姓名")
        else:
            problem = []
            answer = []
            #生成试题
            for i in range(10):
                if random.random() < 0.5:
                    a = random.randint(0,10)
                    b = random.randint(0,10)
                    problem.append(str(a)+"+"+str(b))
                    answer.append(a+b)
                else:
                    c = random.randint(1,10)
                    d = random.randint(0,c)
                    problem.append(str(c) + "-" + str(d))
                    answer.append(c - d)
            answerRight = []
            for i in answer:
                answerRight.append(str(i))
            #输入答案
            self.textEdit_4 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_4,0,1)
            self.textEdit_6 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_6, 1, 1)
            self.textEdit_8 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_8, 2, 1)
            self.textEdit_10 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_10, 3, 1)
            self.textEdit_12 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_12, 4, 1)
            self.textEdit_14 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_14, 0, 4)
            self.textEdit_16 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_16, 1, 4)
            self.textEdit_18 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_18, 2, 4)
            self.textEdit_20 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_20, 3, 4)
            self.textEdit_22 = QtWidgets.QTextEdit()
            self.grid.addWidget(self.textEdit_22, 4, 4)
            #输出试题
            self.textEdit_3.setText(problem[0])
            self.textEdit_5.setText(problem[1])
            self.textEdit_7.setText(problem[2])
            self.textEdit_9.setText(problem[3])
            self.textEdit_11.setText(problem[4])
            self.textEdit_13.setText(problem[5])
            self.textEdit_15.setText(problem[6])
            self.textEdit_17.setText(problem[7])
            self.textEdit_19.setText(problem[8])
            self.textEdit_21.setText(problem[9])
            #刷新试题
            self.textEdit_3.setText(" ")
            self.textEdit_5.setText(" ")
            self.textEdit_7.setText(" ")
            self.textEdit_9.setText(" ")
            self.textEdit_11.setText(" ")
            self.textEdit_13.setText(" ")
            self.textEdit_15.setText(" ")
            self.textEdit_17.setText(" ")
            self.textEdit_19.setText(" ")
            self.textEdit_21.setText(" ")
            #刷新成绩
            self.textEdit_23.setText(" ")
            self.pushButton.setEnabled(False)

    def Submit(self):
        try:
            getanswer = [self.textEdit_4.text(),self.textEdit_6.text(),self.textEdit_8.text(),self.textEdit_10.text(),
                         self.textEdit_12.text(),self.textEdit_14.text(),self.textEdit_16.text(),self.textEdit_18.text(),
                         self.textEdit_20.text(),self.textEdit_22.text(),]
        except NameError:
            QtWidgets.QMessageBox.information(self,"提示","题目未生成")
        else:
            getanswer = [self.textEdit_4.text(),self.textEdit_6.text(),self.textEdit_8.text(),self.textEdit_10.text(),
                         self.textEdit_12.text(),self.textEdit_14.text(),self.textEdit_16.text(),self.textEdit_18text(),
                         self.textEdit_20.text(),self.textEdit_22.text(),]
            if '' in getanswer:
                QtWidgets.QMessageBox.information(self,"提示","题目未完成")
                getanswer.clear()
            else:
                i = 0
                g = 0
                for a in answerRight:
                    if a == getanswer[i]:
                        g = g + 1
                    i = i + 1
                grade = str(g * 10)
                self.textEdit_23.setText(grade)
                #写入到文件
                outfile = open("Exam_puple2020.txt","a+", encoding='gbk')
                outfile.write("-----------------------------" + "\n")
                outfile.write("姓名:" + str(self.textEdit.text()) + "\n")
                outfile.write("学校:"+str(self.textEdit_2.text()) + "\n")
                outfile.write("题目" + str(problem) + "\n")
                outfile.write("学生答案:" + str(getanswer) + "\n")
                outfile.write("正确答案:" + str(answer) + "\n")
                outfile.write("学生成绩:" + str(int(grade)) + "\n")
                outfile.close()
                self.pushButton_3.setEnabled(True)
    def Answer(self):
        self.textEdit_4.setText(answerRight[0])
        self.textEdit_6.setText(answerRight[1])
        self.textEdit_8.setText(answerRight[2])
        self.textEdit_10.setText(answerRight[3])
        self.textEdit_12.setText(answerRight[4])
        self.textEdit_14.setText(answerRight[5])
        self.textEdit_16.setText(answerRight[6])
        self.textEdit_18.setText(answerRight[7])
        self.textEdit_20.setText(answerRight[8])
        self.textEdit_22.setText(answerRight[9])
另一个文件的主函数是
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from c01 import *

class MyWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.setupUi(self)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWin = MyWindow()
    myWin.show()
    sys.exit(app.exec_())





运行结果及报错内容

img

摁哪个按钮都是闪退

  • 写回答

1条回答 默认 最新

  • Ko-walski 2022-11-05 10:37
    关注

    img

    QTextEdit 没有text()属性,而是toPlainText()

    img

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月13日
  • 已采纳回答 11月5日
  • 创建了问题 11月5日

悬赏问题

  • ¥33 集成BiLSTM模型和GCN模型时,前模型的输出不匹配后模型的输入
  • ¥15 关于液体厚度提取,和铺展轨迹数据化处理
  • ¥20 对方微信是wxid如何添加成好友?或者转换成微信号?
  • ¥15 yolov5实验数据好,但是自己拍摄的照片检测结果差
  • ¥15 做过dali2.0认证的技术,
  • ¥15 一道python难题
  • ¥15 matlab 免疫算法
  • ¥50 可视化界面构建,实现信息模块功能
  • ¥15 基于bert-base-chinese的中文文本处理
  • ¥15 高价求抖音抓包技术,抖音抓包无网络问题