This repository has been archived on 2024-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
lessons/Python/clock/main.py

38 lines
871 B
Python
Executable File

import sys
from time import strftime
from PyQt6.QtCore import QTimer
from PyQt6.QtWidgets import QApplication, QLCDNumber, QVBoxLayout, QWidget
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(100, 100, 800, 400)
self.setWindowTitle("Clock")
vbox = QVBoxLayout()
self.timer = QTimer()
self.timer.timeout.connect(self.update_clock)
self.timer.start(200)
self.lcd = QLCDNumber()
vbox.addWidget(self.lcd)
self.setLayout(vbox)
def update_clock(self) -> None:
time_ = strftime("%H:%M:%S")
self.lcd.setDigitCount(8)
self.lcd.display(time_)
def main():
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()