forked from furas/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock-class.py
More file actions
63 lines (41 loc) · 1.25 KB
/
Copy pathclock-class.py
File metadata and controls
63 lines (41 loc) · 1.25 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
#!/usr/bin/env python
#import sys
#
#if sys.version_info.major == 2:
# import Tkinter as tk
#else:
# import tkinter as
try:
import Tkinter as tk # Python 2.x
except:
import tkinter as tk # Python 3.x
from datetime import datetime
# --- constants ---
# empty
# --- classes ---
class Clock(tk.Tk):
def __init__(self):
# create main window and set its title
tk.Tk.__init__(self) # Python 2 & 3
#super().__init__() # Python 3 only
self.title('Time')
# create variable for displayed time and use it with Label
self.txt_var = tk.StringVar()
tk.Label(self, textvariable=self.txt_var).pack()
def update(self):
# 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')
self.txt_var.set(current_time_str)
# rupdate again after 1000ms (1s)
self.after(1000, self.update)
def run(self):
# update first time
self.update()
# start the engine :)
self.mainloop()
# --- functions ---
# empty
# --- main ---
Clock().run()