-
Notifications
You must be signed in to change notification settings - Fork 0
/
after_method_9.py
48 lines (35 loc) · 1.09 KB
/
after_method_9.py
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
import tkinter as tk
from tkinter import ttk
import time
class DigitalClock(tk.Tk):
def __init__(self):
super().__init__()
# configure the root window
self.title('Digital Clock')
self.resizable(0, 0)
self.geometry('250x80')
self['bg'] = 'black'
# change the background color to black
self.style = ttk.Style(self)
self.style.configure(
'TLabel',
background='black',
foreground='red')
# label
self.label = ttk.Label(
self,
text=self.time_string(),
font=('Digital-7', 40))
self.label.pack(expand=True)
# schedule an update every 1 second
self.label.after(1000, self.update)
def time_string(self):
return time.strftime('%H:%M:%S')
def update(self):
""" update the label every 1 second """
self.label.configure(text=self.time_string())
# schedule another timer
self.label.after(1000, self.update)
if __name__ == "__main__":
clock = DigitalClock()
clock.mainloop()