QTimer 使用计时器让程序定时关闭 的案例
QTimer.singleShot
import sys
from PyQt5.QtCore import Qt, QTimer, QDateTime
from PyQt5.QtGui import QIcon, QPalette, QColor
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QMenu, QVBoxLayout, QMainWindow, \
QTreeWidget, QTreeWidgetItem, QHBoxLayout, QPushButton, QInputDialog, QDirModel, QTreeView, QTabWidget, QFormLayout, \
QLineEdit, QRadioButton, QLabel, QCheckBox, QListWidget, QStackedWidget, QDockWidget, QMdiArea, QMdiSubWindow, \
QTextEdit, QScrollBar, QGridLayout
'''
QTimer 使用计时器让程序定时关闭 的案例
QTimer.singleShot
'''
class AutoCloseDemo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 360, 260)
# 设置窗口标题
self.setWindowTitle('QTimer 使用倒计时自动关闭窗口 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
hbox = QHBoxLayout()
self.label = QLabel('你好!窗口将在5秒后自动关闭!')
hbox.addWidget(self.label)
QTimer.singleShot(5000,app.quit)
# self.label.setWindowsFlags(Qt.SplashScreen | Qt.FramelessWindowHint)
self.setLayout(hbox)
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = AutoCloseDemo()
w.show()
sys.exit(app.exec_())