我正在尝试使用Mark Summerfield的Rapid GUI Programing with Python and Qt来学习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。
发布于 2015-03-23 05:35:33
您可以创建一个实例:
QTimer().singleShot(60000, app.quit) 但是QTimer.singleShot(60000, app.quit)只是在编辑器中给出一个警告,它实际上并不会导致错误。
https://stackoverflow.com/questions/29200043
复制相似问题