-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitalClock.py
More file actions
84 lines (69 loc) · 2.55 KB
/
DigitalClock.py
File metadata and controls
84 lines (69 loc) · 2.55 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#################
# Digital Clock #
#################
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QPushButton
from PyQt5.QtGui import QIcon, QFontDatabase, QFont
from PyQt5.QtCore import QTimer, QTime, Qt
class DigitalClock(QWidget):
clock_running = True
def __init__(self):
super().__init__()
self.time_label = QLabel(self)
self.button = QPushButton("Stop", self)
self.initUI()
def initUI(self):
self.setWindowTitle("Genco Digital Clock")
self.setWindowIcon(QIcon("digital.png"))
self.timer = QTimer(self)
self.setGeometry(700, 300, 600, 300)
vbox = QVBoxLayout()
vbox.addWidget(self.time_label)
vbox.addWidget(self.button)
self.setLayout(vbox)
self.time_label.setObjectName("time_label")
self.button.setObjectName("button")
self.time_label.setAlignment(Qt.AlignCenter)
self.setStyleSheet("""
DigitalClock {
background-color: #33322d;
}
QLabel#time_label {
font-size: 150px;
color: #ffec70;
}
QPushButton#button {
font-size: 100px;
border: 10px solid;
border-radius: 20px;
background-color: #ff7e75;
}
""")
font_id = QFontDatabase.addApplicationFont("DS-DIGIT.TTF")
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
digit_font = QFont(font_family, 150)
self.time_label.setFont(digit_font)
self.button.setFont(digit_font)
self.button.clicked.connect(self.button_changed)
self.timer.timeout.connect(self.update_time)
self.timer.start(1000) # miliseconds
self.update_time()
def update_time(self):
current_time = QTime.currentTime().toString("hh:mm:ss")
self.time_label.setText(current_time)
def button_changed(self):
if self.clock_running == True:
self.timer.stop()
self.button.setText("Start")
self.button.setStyleSheet("background-color: #95fa8c;")
self.clock_running = False
else:
self.timer.start(1000)
self.button.setText("Stop")
self.button.setStyleSheet("background-color: #ff7e75;")
self.clock_running = True
if __name__ == "__main__":
app = QApplication(sys.argv)
clock = DigitalClock()
clock.show()
sys.exit(app.exec_())