Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import *
- import tkinter as tk
- from math import *
- import math
- def gettime():
- txt = time.ctime()
- return int(txt[11:13]),int(txt[14:16]),int(txt[17:19])
- class tarcza:
- def __init__(self, kanwa):
- self.kanwa = kanwa
- self.konfig()
- self.rysuj()
- self.wskazowki()
- def konfig(self):
- self.wys = int(self.kanwa.config('height')[-1])
- self.szer = int(self.kanwa.config('width')[-1])
- self.x0,self.y0=self.szer/2, self.wys/2
- self.Rmax = min(self.x0,self.y0)
- def rysuj(self):
- godzina = 12
- for alfa in range(90,421,30):
- self.linia(self.Rmax-50, alfa, self.Rmax-70, alfa)
- self.podpis( self.Rmax-20, alfa, str(godzina))
- godzina -= 1
- def podpis (self, r, alfa, txt):
- x=self.x0 + r*math.cos(math.radians(alfa))
- y=self.y0 - r*math.sin(math.radians(alfa))
- kanwa.create_text(x,y,text=txt, fill='blue', font=('Arial',18))
- def linia(self, r1, alfa1, r2, alfa2):
- x1=self.x0 + r1*math.cos(math.radians(alfa1))
- y1=self.y0 - r1*math.sin(math.radians(alfa1))
- x2=self.x0 + r2*math.cos(math.radians(alfa1))
- y2=self.y0 - r2*math.sin(math.radians(alfa1))
- kanwa.create_line(x1,y1,x2,y2,width=5)
- def wskazowki(self):
- x0 = 600/2; lx = 9*600/20
- y0 = 600/2; ly = 9*600/20
- r1 = 0.9 * min(lx,ly)
- r2 = 0.6 * min(lx,ly)
- r3 = 0.8 * min(lx,ly)
- t = localtime()
- t_s = t[5]
- t_m = t[4] + t_s/60
- t_h = t[3] % 12 + t_m/60
- phi1 = pi/6 * t_h
- x = x0 + r1 * sin(phi1)
- y = y0 - r1 * cos(phi1)
- kanwa.create_line(x0, y0, x, y, fill="red", width=3)
- phi2 = pi/30 * t_m
- x = x0 + r2 * sin(phi2)
- y = y0 - r2 * cos(phi2)
- kanwa.create_line(x0, y0, x, y, fill="blue", width=2)
- phi3 = pi/30 * t_s
- x = x0 + r2 * sin(phi3)
- y = y0 - r2 * cos(phi3)
- kanwa.create_line(x0, y0 , x, y)
- def zegar(kanwa):
- kanwa.delete("all")
- tarcza(kanwa)
- kanwa.after(10, zegar, kanwa)
- if __name__ == '__main__':
- app = tk.Tk()
- app.title('Zegarek')
- kanwa = tk.Canvas(app, width = 600, height = 600)
- kanwa.pack()
- ## T=tarcza(kanwa)
- W=zegar(kanwa)
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement