-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_Clock_1.py
More file actions
57 lines (41 loc) · 1.23 KB
/
Copy pathPython_Clock_1.py
File metadata and controls
57 lines (41 loc) · 1.23 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
#!/bin/env python2
# -*- coding: utf-8 -*-
"""
http://effbot.org/tkinterbook/
karl.lv@outlook.com
June 6, 2018
"""
from Tkinter import *
import time
import threading
def show_time():
while 1:
cur_time = time.strftime('%Y-%m-%d %X', time.localtime())
print cur_time
time.sleep(1)
class Clock(Tk):
def __init__(self):
self.tk = Tk()
self.tk.title("A Clock App")
self.add_label_time()
thd = threading.Thread(target=self.main_start, args=())
thd.start()
def add_label_time(self):
cur_time = time.strftime('%Y-%m-%d %X', time.localtime())
self.label_time = Label(self.tk, text=cur_time, font=("Helvetica", 30), bd=10, bg="green", width=20, justify=LEFT, relief=GROOVE)
self.label_time.grid(row=0, column=0, ipadx=20, ipady=20, padx=20, pady=20)
def show_time(self):
cur_time = time.strftime('%Y-%m-%d %X', time.localtime())
print cur_time
self.label_time.config(text=cur_time)
def main_start(self):
print "main_start"
while True:
self.show_time()
time.sleep(1)
def main():
print "A Clock App"
app = Clock()
app.mainloop()
if __name__ == '__main__':
main()