設置定時器對整個程序進行關閉
""" 讓程序定時關閉 QTimer.singleShot """ import sys from typing import Union from PyQt5.QtWidgets import * from PyQt5.QtCore import QTimer, QDateTime from PyQt5.QtGui import * from PyQt5.QtCore import * if __name__ == "__main__": app = QApplication(sys.argv) #構造標簽 label = QLabel("<font color=red size=140><b>Hello World, 窗口在5秒后自動關閉!</b></font>") #作為窗口提示 label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint) #進行標簽顯示 label.show() #一定時間后進行關閉 QTimer.singleShot(5000, app.quit) sys.exit(app.exec_())