-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalog--clock--with--python.py
69 lines (61 loc) · 1.83 KB
/
analog--clock--with--python.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
try:
import Tkinter
except:
import tkinter as Tkinter
import math # Required For Coordinates Calculation
import time # Required For Time Handling
#
#
# class
class main(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.x=150 # Center Point x
self.y=150 # Center Point
self.length=50 # Stick Length
self.creating_all_function_trigger()
# Creating Trigger For Other Functions
def creating_all_function_trigger(self):
self.create_canvas_for_shapes()
self.creating_background_()
self.creating_sticks()
return
# Creating Background
def creating_background_(self):
self.image=Tkinter.PhotoImage(file='clock.gif')
self.canvas.create_image(150,150, image=self.image)
return
# creating Canvas
def create_canvas_for_shapes(self):
self.canvas=Tkinter.Canvas(self, bg='black')
self.canvas.pack(expand='yes',fill='both')
return
# Creating Moving Sticks
def creating_sticks(self):
self.sticks=[]
for i in range(3):
store=self.canvas.create_line(self.x, self.y,self.x+self.length,self.y+self.length,width=2, fill='red')
self.sticks.append(store)
return
# Function Need Regular Update
def update_class(self):
now=time.localtime()
t = time.strptime(str(now.tm_hour), "%H")
hour = int(time.strftime( "%I", t ))*5
now=(hour,now.tm_min,now.tm_sec)
# Changing Stick Coordinates
for n,i in enumerate(now):
x,y=self.canvas.coords(self.sticks[n])[0:2]
cr=[x,y]
cr.append(self.length*math.cos(math.radians(i*6)-math.radians(90))+self.x)
cr.append(self.length*math.sin(math.radians(i*6)-math.radians(90))+self.y)
self.canvas.coords(self.sticks[n], tuple(cr))
return
# Main Function Trigger
if __name__ == '__main__':
root=main()
# Creating Main Loop
while True:
root.update()
root.update_idletasks()
root.update_class()