-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalogClock.py
More file actions
57 lines (46 loc) · 2 KB
/
AnalogClock.py
File metadata and controls
57 lines (46 loc) · 2 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
from tkinter import *
from PIL import Image, ImageTk, ImageDraw
from datetime import *
import time
from math import *
class Clock:
def __init__(self, root):
self.root = root
self.root.title("Analog Clock")
self.root.geometry("1350x700+0+0")
self.root.config(bg="#021e2f")
title = Label(self.root, text="Analog Clock", font=("roboto", 50, "bold"), bg="#04444a", fg="white").place(x=0, y=50, relwidth=1)
self.lbl = Label(self.root, bg="white", bd=20, relief=RAISED)
self.lbl.place(x=475, y=200, height=400, width=400)
self.working()
def clock_image(self, hr, min_, sec_):
clock =Image.new("RGB", (400, 400), (255,255,255))
draw = ImageDraw.Draw(clock)
# Draw clock Image-----------------
bg=Image.open("Image/cl.jpg")
bg=bg.resize((300,300), Image.ANTIALIAS)
clock.paste(bg, (50,50))
origin = 200,200
# Draw Hour line Image-----------------
draw.line((origin,200+50*sin(radians(hr)),200-50*cos(radians(hr))), fill="black", width=3)
# Draw Minute line Image-----------------
draw.line((origin,200+80*sin(radians(min_)),200-80*cos(radians(min_))), fill="blue", width=3)
# Draw Second line Image-----------------
draw.line((origin,200+100*sin(radians(sec_)),200-100*cos(radians(sec_))), fill="green", width=3)
# Draw circle Image-----------------
draw.ellipse((195,195,210,210), fill="black")
clock.save("Image/clock_new.png")
def working(self):
h = datetime.now().time().hour
m = datetime.now().time().minute
s = datetime.now().time().second
hr = (h/12)*360
min_ = (m/60)*360
sec_ = (s/60)*360
self.clock_image(hr, min_, sec_)
self.img = ImageTk.PhotoImage(file="Image/clock_new.png")
self.lbl.config(image=self.img)
self.lbl.after(200, self.working)
root = Tk()
obj = Clock(root)
root.mainloop()