1 importsys 2 from PyQt5.QtCore importQTimer, Qt 3 from PyQt5.QtWidgets importQApplication, QWidget, QPushButton, QLabel, QVBoxLayout 4 5 classDemo(QWidget): 6 def __init__(self): 7 super(Demo, self).__init__() 8 self.label = QLabel('0', self) 9 self.label.setAlignment(Qt.AlignCenter) 10 11 self.step =0 12 13 self.timer = QTimer(self) #实例化定时器 14 self.timer.timeout.connect(self.update_func) #设置定时执行的函数 15 16 self.ss_button = QPushButton('Start', self) 17 self.ss_button.clicked.connect(self.start_stop_func) 18 19 self.v_layout =QVBoxLayout() 20 self.v_layout.addWidget(self.label) 21 self.v_layout.addWidget(self.ss_button) 22 23 self.setLayout(self.v_layout) 24 25 defstart_stop_func(self): 26 if notself.timer.isActive(): 27 #self.timer.isActive() 返回定时器是否激活 Ture激活 28 self.ss_button.setText('Stop') 29 self.timer.start(100) #启动定时器,时间间隔100毫秒 30 else: 31 self.ss_button.setText('Start') 32 self.timer.stop() #停止定时器 33 34 defupdate_func(self): 35 self.step += 1 36 self.label.setText(str(self.step)) 37 38 39 if __name__ == '__main__': 40 app =QApplication(sys.argv) 41 demo =Demo() 42 demo.show() 43 sys.exit(app.exec_())
定时器QTimer
免责声明:文章转载自《定时器QTimer》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇docker pull报x509问题及docker启动失败问题解决使用Keras进行深度学习:(二)CNN讲解及实践下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=