Секундомер не включается после нажатия Button
import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QGridLayout, QSizePolicy, QApplication
global QPushButton
button = QPushButton
class Window(QWidget):
def __init__(self, *args, **kwargs):
self.my_counter = 0 ## replaced "1"
self.my_counter1 = 0
self.my_counter2 = 0
QWidget.__init__(self, *args, **kwargs)
# self.label = QLabel("Q", self) #original
self.label = QLabel(self)
self.label1 = QLabel(self)
self.label2 = QLabel(self)
self.label.setText("00")
self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.label.setAlignment(Qt.AlignCenter)
self.label.setStyleSheet("QLabel {background-color: white; font-size: 30pt;}")
self.label1 = QLabel(self)
self.label1.setAlignment(Qt.AlignCenter)
self.label1.setStyleSheet("QLabel {background-color: white; font-size: 30pt;}")
self.label1.setText("00.")
self.label2 = QLabel(self)
self.label2.setAlignment(Qt.AlignCenter)
self.label2.setStyleSheet("QLabel {background-color: pink; font-size: 30pt;}")
self.label2.setText("00:")
self.button = QPushButton(self)
self.button.setStyleSheet("QPushButton {background-color: yellow; font-size: 15pt;}")
self.button.setText("Start")
self.layout = QGridLayout(self)
self.layout.addWidget(self.label, 0, 4)
self.layout.addWidget(self.label1, 0, 3) # New label1
self.layout.addWidget(self.label2, 0, 2) # + New label2
self.layout.addWidget(self.button, 3, 3)
self.setLayout(self.layout)
self.show()
def local_button_handler(self):
self.label.setText("%d" % self.my_counter)
self.my_counter += 1
if self.my_counter == 100:
self.my_counter = 0
self.my_counter1 += 1
self.label1.setText("%d" % self.my_counter1 + ".")
if self.my_counter1 == 60:
self.label1.setText("00.")
self.my_counter1 = 0
self.my_counter2 += 1
self.label2.setText("0"+"%d" % self.my_counter2 + ":")
elif self.my_counter1 < 10:
self.label1.setText("0" + "%d" % self.my_counter1 + ".")
elif self.my_counter < 10:
self.label.setText("0" + "%d" % self.my_counter)
def on_button_clicked(self):
button.clicked.connect(win.local_button_handler())
timer = QTimer()
timer.timeout.connect(win.local_button_handler)
timer.start(10)
on_button_clicked
app = QApplication(sys.argv)
win = Window()
#
# timer = QTimer()
# timer.timeout.connect(win.local_button_handler)
# timer.start(10)
app.exec_()
sys.exit(app.exec_())
Перемещено Zhbert из general