-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitalclock.py
More file actions
40 lines (31 loc) · 1.12 KB
/
digitalclock.py
File metadata and controls
40 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5.QtCore import QTimer, QTime, Qt
class DigitalClock(QWidget):
def __init__(self):
super().__init__()
self.time_label = QLabel(self)
self.timer = QTimer(self)
self.initUI()
def initUI(self):
self.setWindowTitle("Digital Clock")
self.setGeometry(400, 300, 380, 100)
vbox = QVBoxLayout()
vbox.addWidget(self.time_label)
self.setLayout(vbox)
self.time_label.setStyleSheet("font-size: 100px;" "color: hsl(122, 96%, 45%);" "font-family: arial;")
self.time_label.setAlignment(Qt.AlignCenter)
self.setStyleSheet("background: black;")
self.timer.timeout.connect(self.update_time)
self.timer.start(1000)
self.update_time()
def update_time(self):
current_time = QTime.currentTime().toString("hh:mm:ss AP")
self.time_label.setText(current_time)
def main():
app = QApplication(sys.argv)
clock = DigitalClock()
clock.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()