From 91c8cad0749dc9978f4afb5ac2c4af5723dd3077 Mon Sep 17 00:00:00 2001 From: helldh Date: Wed, 24 Dec 2025 10:58:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20oop-exam/timer.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oop-exam/timer.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 oop-exam/timer.py diff --git a/oop-exam/timer.py b/oop-exam/timer.py new file mode 100644 index 0000000..a5e4931 --- /dev/null +++ b/oop-exam/timer.py @@ -0,0 +1,43 @@ +import sys +from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout +from PyQt6.QtCore import QTimer + +class SimpleTimer(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("Таймер") + + self.label = QLabel("0") + self.seconds = 0 + + self.start_button = QPushButton("Старт") + self.start_button.clicked.connect(self.start_timer) + + self.stop_button = QPushButton("Стоп") + self.stop_button.clicked.connect(self.stop_timer) + + layout = QVBoxLayout() + layout.addWidget(self.label) + layout.addWidget(self.start_button) + layout.addWidget(self.stop_button) + self.setLayout(layout) + + self.timer = QTimer() + self.timer.timeout.connect(self.update_time) # вызывается каждый тик + self.timer.setInterval(1000) # 1000 мс = 1 секунда + + def start_timer(self): + self.timer.start() + + def stop_timer(self): + self.timer.stop() + + def update_time(self): + self.seconds += 1 + self.label.setText(str(self.seconds)) + +if __name__ == "__main__": + app = QApplication(sys.argv) + timer = SimpleTimer() + timer.show() + sys.exit(app.exec()) \ No newline at end of file