from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class TestWindow(QDialog):
def __init__(self):
super(TestWindow,self).__init__()
self.currentLoopNum=0
self.testPushBotton=QPushButton(self)
self.testPushBotton.setText("Start")
self.stopPushBotton=QPushButton(self)
self.stopPushBotton.setText("Stop")
self.testLabel=QLabel(self)
self.testLayout=QGridLayout(self)
self.testLayout.addWidget(self.testPushBotton,0,0)
self.testLayout.addWidget(self.stopPushBotton,0,1)
self.testLayout.addWidget(self.testLabel,1,0,1,2)
self.testTimer=QTimer(self)
self.connect(self.testPushBotton,SIGNAL("clicked()"),self.doSomething)
self.connect(self.testTimer,SIGNAL("timeout()"),self.timeOut)
self.connect(self.stopPushBotton,SIGNAL("clicked()"),self.stopTimer)
def doSomething(self):
self.testTimer.start(1000)
def timeOut(self):
self.currentLoopNum+=1
self.testLabel.setText(str(self.currentLoopNum))
def stopTimer(self):
self.testTimer.stop()
app=QApplication(sys.argv)
form=TestWindow()
form.show()
app.exec_()