尝试更改标签时,为什么我的PyQT窗口关闭?

时间:2019-04-13 20:59:56

标签: python pyqt5

我正在尝试制作一个更新PyQT5中标签的程序,但是我遇到了问题。当我启动它时,它可以正常工作,但是当它更新标签时,它关闭。

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
import time
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(585, 236)
        MainWindow.setStyleSheet("font: 75 14pt \"Arial\";")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(30, 10, 47, 13))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(170, 10, 47, 13))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(280, 10, 141, 16))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(430, 10, 141, 16))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(20, 50, 101, 16))
        self.label_5.setStyleSheet("font: 9pt \"MS Shell Dlg 2\";")
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(140, 50, 101, 16))
        self.label_6.setStyleSheet("font: 9pt \"MS Shell Dlg 2\";")
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(440, 50, 101, 16))
        self.label_7.setStyleSheet("font: 9pt \"MS Shell Dlg 2\";")
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setGeometry(QtCore.QRect(290, 50, 101, 16))
        self.label_8.setStyleSheet("font: 9pt \"MS Shell Dlg 2\";")
        self.label_8.setObjectName("label_8")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "LS"))
        self.label_2.setText(_translate("MainWindow", "SF"))
        self.label_3.setText(_translate("MainWindow", "Red County"))
        self.label_4.setText(_translate("MainWindow", "Flint County "))
        self.label_5.setText(_translate("MainWindow", "lszoveg"))
        self.label_6.setText(_translate("MainWindow", "sfzoveg"))
        self.label_7.setText(_translate("MainWindow", "fcszoveg"))
        self.label_8.setText(_translate("MainWindow", "rcszoveg"))
def update_label() :
   self.label_8.setText("rcszoveg2")

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QWidget()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    timer = QTimer()
    timer.timeout.connect(update_label)
    timer.start(1000)

    sys.exit(app.exec_())

它没有给出任何错误消息,所以我什至无法意识到问题是什么。感谢您的帮助,我非常感谢。

0 个答案:

没有答案