python - PyQt4 QTimer doesn't work -
i'm new use pyqt4 qtimer. copy code somewhere seems doesn't work. can me this?
from pyqt4 import qtcore, qtgui pyqt4.qtgui import * pyqt4.qtcore import * def startcount(): timer.start(1000) def shownum(): global count count = count + 1 return count timer = qtcore.qtimer() count = 0 timer.timeout.connect(shownum) startcount()
i expect see count incremented time, console shows nothing output. can explain this?
a qtimer
cannot work without running event-loop. try instead:
import sys pyqt4 import qtcore, qtgui def startcount(): timer.start(1000) def shownum(): global count count = count + 1 print(count) if count > 10: app.quit() app = qtcore.qcoreapplication(sys.argv) timer = qtcore.qtimer() count = 0 timer.timeout.connect(shownum) startcount() app.exec_()
Comments
Post a Comment