我正在尝试使用Mark Summerfield使用Python和Qt进行快速GUI编程来学习PyQt。但是,我坚持第一个例子。 (我使用的是Python 2.7)
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
try:
due = QTime.currentTime()
message = "Alert!"
if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].split(":")
due = 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: alert.pyw HH:MM [optional message]"
while QTime.currentTime() < due:
time.sleep(20) # 20 seconds
label = 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_()
倒数第二行,即QTimer.singleShot(60000, app.quit)
给出错误,预期类型为'QTimer',而是'int'。当我查找方法定义时,看起来第一个参数应该是一个int。
答案 0 :(得分:0)
您可以创建一个实例:
QTimer().singleShot(60000, app.quit)
但是QTimer.singleShot(60000, app.quit)
只是在编辑器中发出警告,它实际上并没有导致错误。