PyQt5初级阶段

1 一个闹钟

import sys
import time

from PyQt5 import QtCore
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QApplication

#先创建一个app实例
app = QApplication(sys.argv)

# handle the argv
try:
    due = QtCore.QTime.currentTime()
    message = 'Alert!'
    if len(sys.argv) < 2:
        raise ValueError
    hours, mins = sys.argv[1].split(':')
    due = QtCore.QTime(int(hours), int(mins))
    if not due.isValid():
        raise ValueError
    if len(sys.argv) > 2:
        message = ' '.join(sys.argv[2:])
        
except ValueError:
    message = 'Usage: alarm_clock.py HH:MM [optional message]'

while QtCore.QTime.currentTime() < due:
    print(QtCore.QTime.currentTime())
    time.sleep(1)

#设定标签内容,然后show这个标签
#调用一个单次触发器,6w毫秒(1min)后,触发app.quit。
label = QLabel('<font color=red size=72><b>' + message + '</b></font>')
label.show()
QtCore.QTimer.singleShot(60000, app.quit)

#执行app实例
app.exec_()

  

猜你喜欢

转载自www.cnblogs.com/jabbok/p/9330381.html
今日推荐