Skip to content

Commit 909124f

Browse files
authored
Update clock.py
1 parent 1a68e9e commit 909124f

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

DigitalClock/clock.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
# import GUI library - Tkinter
2-
from tkinter import *
2+
import tkinter as tk
33
import time
44

5-
root = Tk()
5+
class Clock:
6+
def __init__(self):
7+
self.master = tk.Tk()
68

7-
# Label the window to "My Clock"
8-
root.title('My Clock')
9+
def settings(self):
10+
# Label the window to "My Clock"
11+
self.master.title('My Clock')
912

10-
#Time calculation
11-
def counttime(time1=''):
12-
time2 = time.strftime('%H:%M:%S')
13-
if time2 != time1:
14-
time1 = time2
15-
clock.config(text=time2)
16-
clock.after(200, counttime)
13+
def widgets(self):
14+
#Time calculation
15+
def counttime(time1=''):
16+
time2 = time.strftime('%H:%M:%S')
17+
if time2 != time1:
18+
time1 = time2
19+
clock.config(text=time2)
20+
clock.after(200, counttime)
21+
# Create the clock text
22+
clock = tk.Label(self.master, font=('Poppins', 50, 'bold'), background='blue', foreground='white')
23+
clock.pack(anchor='center')
24+
# Clock loop
25+
counttime()
26+
tk.mainloop()
1727

18-
# Create the clock text
19-
clock = Label(root, font=('Poppins', 50, 'bold'), background='blue', foreground='white')
20-
clock.pack(anchor='center')
21-
22-
# Clock loop
23-
counttime()
24-
mainloop()
28+
if __name__ == '__main__':
29+
my_clock = Clock()
30+
my_clock.settings()
31+
my_clock.widgets()

0 commit comments

Comments
 (0)