Advertisement
Guest User

Zegarek dzialajacy

a guest
Feb 7th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. from time import *
  2. import tkinter as tk
  3. from math import *
  4. import math
  5.  
  6.  
  7. def gettime():
  8. txt = time.ctime()
  9. return int(txt[11:13]),int(txt[14:16]),int(txt[17:19])
  10.  
  11. class tarcza:
  12. def __init__(self, kanwa):
  13. self.kanwa = kanwa
  14. self.konfig()
  15. self.rysuj()
  16. self.wskazowki()
  17.  
  18. def konfig(self):
  19. self.wys = int(self.kanwa.config('height')[-1])
  20. self.szer = int(self.kanwa.config('width')[-1])
  21. self.x0,self.y0=self.szer/2, self.wys/2
  22. self.Rmax = min(self.x0,self.y0)
  23.  
  24.  
  25. def rysuj(self):
  26. godzina = 12
  27. for alfa in range(90,421,30):
  28. self.linia(self.Rmax-50, alfa, self.Rmax-70, alfa)
  29. self.podpis( self.Rmax-20, alfa, str(godzina))
  30. godzina -= 1
  31.  
  32. def podpis (self, r, alfa, txt):
  33. x=self.x0 + r*math.cos(math.radians(alfa))
  34. y=self.y0 - r*math.sin(math.radians(alfa))
  35. kanwa.create_text(x,y,text=txt, fill='blue', font=('Arial',18))
  36.  
  37. def linia(self, r1, alfa1, r2, alfa2):
  38. x1=self.x0 + r1*math.cos(math.radians(alfa1))
  39. y1=self.y0 - r1*math.sin(math.radians(alfa1))
  40. x2=self.x0 + r2*math.cos(math.radians(alfa1))
  41. y2=self.y0 - r2*math.sin(math.radians(alfa1))
  42. kanwa.create_line(x1,y1,x2,y2,width=5)
  43.  
  44.  
  45. def wskazowki(self):
  46. x0 = 600/2; lx = 9*600/20
  47. y0 = 600/2; ly = 9*600/20
  48. r1 = 0.9 * min(lx,ly)
  49. r2 = 0.6 * min(lx,ly)
  50. r3 = 0.8 * min(lx,ly)
  51.  
  52. t = localtime()
  53. t_s = t[5]
  54. t_m = t[4] + t_s/60
  55. t_h = t[3] % 12 + t_m/60
  56.  
  57.  
  58. phi1 = pi/6 * t_h
  59. x = x0 + r1 * sin(phi1)
  60. y = y0 - r1 * cos(phi1)
  61. kanwa.create_line(x0, y0, x, y, fill="red", width=3)
  62.  
  63.  
  64. phi2 = pi/30 * t_m
  65. x = x0 + r2 * sin(phi2)
  66. y = y0 - r2 * cos(phi2)
  67. kanwa.create_line(x0, y0, x, y, fill="blue", width=2)
  68.  
  69.  
  70. phi3 = pi/30 * t_s
  71. x = x0 + r2 * sin(phi3)
  72. y = y0 - r2 * cos(phi3)
  73. kanwa.create_line(x0, y0 , x, y)
  74.  
  75.  
  76. def zegar(kanwa):
  77. kanwa.delete("all")
  78. tarcza(kanwa)
  79. kanwa.after(10, zegar, kanwa)
  80.  
  81.  
  82. if __name__ == '__main__':
  83. app = tk.Tk()
  84. app.title('Zegarek')
  85. kanwa = tk.Canvas(app, width = 600, height = 600)
  86. kanwa.pack()
  87.  
  88. ## T=tarcza(kanwa)
  89. W=zegar(kanwa)
  90.  
  91.  
  92. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement