我有以下功能,QTimer用于每秒更新counter一次1:
def somefunc():
if self.pushButton_13.text() == 'OFF':
self.pushButton_13.setText('ON')
timer1.setInterval(1000) #timer1 is global variable
timer1.timeout.connect(lambda: self.counter(15))
timer1.start()
else:
self.pushButton_13.setText('OFF')
timer1.stop()
print timer1.timerId()
def counter(self, var):
if var == 15:
count = int(str(self.lineEdit_15.text()))
count = count + 1
print count
self.lineEdit_15.setText(QtCore.QString(str(count)))
当我第一次按下按钮counter工作正常但如果再次单击按钮停止计时器然后再次重新启动时,计数器值2每秒更新一次1- 而应该更新1. 同样,如果我再次单击按钮以停止计数器并再次重新启动,则计数器更新3等等。我在哪里犯错?