# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'E:\testPyQt5\dialog2.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import *
import sys
global sec
sec=0
class MyQWidget(QWidget):
def __init__(self, parent=None):
super(MyQWidget, self).__init__(parent)
# self.Date(self)
# def Date(self):
self.setWindowTitle('自动计数')
self.label = QLabel('显示当前数值')
lcdNumber=QLCDNumber()
self.startBtn = QPushButton('开始')
self.endBtn = QPushButton('结束')
layout = QGridLayout(self)
self.timer.timeout.connect(self.showValue)
layout.addWidget(lcdNumber)
layout.addWidget(self.label, 0, 0, 1, 2)
layout.addWidget(self.startBtn, 1, 0)
layout.addWidget(self.endBtn, 1, 1)
self.startBtn.clicked.connect(self.startValue)
self.endBtn.clicked.connect(self.endValue)
self.setLayout(layout)
def showValue(self):
global sec
sec+=1
lcdNumber.display(sec)
def startValue(self):
self.timer.start(1000)
self.startBtn.setEnabled(Flase)
self.endBtn.setEnabled(True)
def endValue(self):
self.timer.stop()
self.startBtn.setEnabled(True)
self.endBtn.setEnabled(False)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
widget =QWidget()
widget.show()
sys.exit(app.exec_())