i使程序显示消息并在一段时间后更改消息,但是如果您关闭程序,它不会仅关闭窗口,请帮助如何关闭所有代码
此代码:
from PyQt5.QtWidgets import *
from PyQt5 import QtCore,QtGui
from threading import Timer
class s:
def UI(self, window):
window.setFixedHeight(500)
window.setFixedWidth(600)
self.Label = QLabel(window)
self.Label.setGeometry(0, 0, 600, 500)
self.Label.setAlignment(QtCore.Qt.AlignCenter)
self.Label.setStyleSheet('font-size:100px')
def mone():
self.Label.setText('Hello')
Tim = Timer(3, mtwo)
Tim.start()
def mtwo():
Tim = Timer(3, mthree)
self.Label.setText('World')
Tim.start()
def mthree():
Tim = Timer(1, mfour)
self.Label.setText('To')
Tim.start()
def mfour():
Tim = Timer(1.5, mfive)
self.Label.setText('My')
Tim.start()
def mfive():
Tim = Timer(10, mone)
self.Label.setText('Program')
Tim.start()
mone()
def pd(self):
print('d')
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
form = QMainWindow()
sd = s()
sd.UI(form)
form.show()
sys.exit(app.exec_())
QtCore.QTimer
代替threading.Timer
,例如(请注意,QTimer
中的时间间隔以毫秒为单位)