Удалить oop-exam/timer.py
This commit is contained in:
parent
a6c27529b0
commit
ce05b61076
1 changed files with 0 additions and 43 deletions
|
|
@ -1,43 +0,0 @@
|
|||
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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue