from datetime import datetime
import math
from tkinter import*
class StillClock(Canvas):
def __init__(self):
super().__init__()
self.setcurrenttime()
self.pack()
self.mainloop()
def gethour(self):
return self.__hour
def sethour(self,hour):
self.__hour=hour
def getminute(self):
return self.__minute
def setminute(self,minute):
self.__minute=minute
def getsecond(self):
return self.__second
def setsecond(self,second):
self.__second=second
def setcurrenttime(self):
d=datetime.now()
self.__hour=d.hour
self.__minute=d.minute
self.__second=d.second
self.delete('clock')
self.drawclock()
def drawclock(self):
width=400
height=250
radius=min(width,height)/3
secondlength=radius*0.8
minutelength=radius*0.6
hourlength=radius*0.4
self.create_oval(width/2-radius,height/2-radius,width/2+radius,height/2+radius,tags='clock')
self.create_text(width/2,height/2-radius,text='12',tags='clock')
self.create_text(width/2+radius,height/2,text='3',tags='clock')
self.create_text(width/2,height/2+radius,text='6',tags='clock')
self.create_text(width/2-radius,height/2,text='9',tags='clock')
xcenter=width/2
ycenter=height/2
xhour=width/2+hourlength*math.sin((2*math.pi)/12*(self.__hour+self.__minute/60))
yhour=height/2-hourlength*math.cos((2*math.pi)/12*(self.__hour+self.__minute/60))
xminute=width/2+minutelength*math.sin((2*math.pi)/60*self.__minute)
yminute=height/2-minutelength*math.cos((2*math.pi)/60*self.__minute)
xsecond=width/2+secondlength*math.sin((2*math.pi)/60*self.__second)
ysecond=height/2-secondlength*math.cos((2*math.pi)/60*self.__second)
self.create_line(xcenter,ycenter,xhour,yhour,tags='clock')
self.create_line(xcenter,ycenter,xminute,yminute,tags='clock')
self.create_line(xcenter,ycenter,xsecond,ysecond,tags='clock')
StillClock()