-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathDigital clock
122 lines (92 loc) · 2.94 KB
/
Digital clock
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from tkinter import *
import time
def display_time():
hour = str(time.strftime("%H"))
minute = str(time.strftime("%M"))
second = str(time.strftime("%S"))
if int(hour) >= 12 and int(hour) < 24 and int (minute) >= 0:
meridiem_label.config(text = "PM")
else:
meridiem_label.config(text = "AM")
if int(hour) > 12:
hour = str((int(hour) - 12))
elif int(hour) == 0:
hour = str(12)
hour_label.config(text = hour)
minute_label.config(text = minute)
second_label.config(text = second)
hour_label.after(200, display_time)
# main function
if __name__ == "__main__":
# creating an object of the Tk() class
gui_root = Tk()
# setting the title of the window
gui_root.title("Digital Clock - JAVATPOINT")
# setting the size and position of the window
gui_root.geometry("650x250+650+250")
# disabling the resizable option for better UI
gui_root.resizable(0, 0)
# configuring the background color to #2C3C3F
gui_root.config(bg = "#2C3C3F")
header_frame = Frame(gui_root, bg = "#2C3C3F")
body_frame = Frame(gui_root, bg = "#2C3C3F")
header_frame.pack(pady = 15)
body_frame.pack()
header_label = Label(
header_frame,
text = "Digital Clock",
font = ("consolas", "14", "bold"),
bg = "#2C3C3F",
fg = "#CAF6FF"
)
header_label.pack()
hour_label = Label(
body_frame,
text = "00",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
colon_label_one = Label(
body_frame,
text = ":",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
minute_label = Label(
body_frame,
text = "00",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
colon_label_two = Label(
body_frame,
text = ":",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
second_label = Label(
body_frame,
text = "00",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
meridiem_label = Label(
body_frame,
text = "AM",
font = ("radioland", "48"),
bg = "#2C3C3F",
fg = "#00D2FF"
)
hour_label.grid(row = 0, column = 0, padx = 5, pady = 5)
colon_label_one.grid(row = 0, column = 1, padx = 5, pady = 5)
minute_label.grid(row = 0, column = 2, padx = 5, pady = 5)
colon_label_two.grid(row = 0, column = 3, padx = 5, pady = 5)
second_label.grid(row = 0, column = 4, padx = 5, pady = 5)
meridiem_label.grid(row = 0, column = 5, padx = 5, pady = 5)
display_time()
gui_root.mainloop()