本文主要是介绍pyqt5 第一个人机交互界面 弹出式闹钟(1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 代码
#!/usr/bin/env python
# Copyright (c) 2007-8 Qtrac Ltd. All rights reserved.
# This program or module is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 2 of the License, or
# version 3 of the License, or (at your option) any later version. It is
# provided for educational purposes and is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
# from PyQt5.QtWidgets import QApplicationfrom PyQt5.QtWidgets import *app = QApplication(sys.argv)try:due = QTime.currentTime()message = "Alert!"if len(sys.argv) < 2:raise ValueErrorhours, mins = sys.argv[1].split(":")due = QTime(int(hours), int(mins))if not due.isValid():raise ValueErrorif len(sys.argv) > 2:message = " ".join(sys.argv[2:])
except ValueError:message = "Usage: alert.pyw HH:MM [optional message]" # 24hr clockwhile QTime.currentTime() < due:time.sleep(20) # 20 secondslabel = QLabel("<font color=red size=72><b>" + message + "</b></font>")
label.setWindowFlags(Qt.SplashScreen)
label.show()
QTimer.singleShot(60000, app.quit) # 1 minute
app.exec_()
保存为alert.pyw
运行python alert.pyw 10:00 wake
参考:
1.源代码下载
这篇关于pyqt5 第一个人机交互界面 弹出式闹钟(1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!