-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathclock-function.py
More file actions
47 lines (32 loc) · 928 Bytes
/
clock-function.py
File metadata and controls
47 lines (32 loc) · 928 Bytes
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
#!/usr/bin/env python
try:
import Tkinter as tk # Python 2.x
except:
import tkinter as tk # Python 3.x
from datetime import datetime
# --- constants ---
# empty
# --- classes ---
# empty
# --- functions ---
def update_time():
# update displayed time
current_time = datetime.now()
current_time_str = current_time.strftime('%Y.%m.%d %H:%M:%S')
# current_time_str = datetime.now().strftime('%Y.%m.%d %H:%M:%S')
label['text'] = current_time_str
# run update_time again after 1000ms (1s)
root.after(1000, update_time)
# --- main ---
# create main window and set its title
root = tk.Tk()
root.title('Time')
# create variable for displayed time and use it with Label
label = tk.Label(root)
label.pack()
# run update_time first time
update_time()
# or run update_time first time after 1000ms (1s)
# root.after(1000, update_time)
# start the engine :)
root.mainloop()