python Tk 为您报时

1922阅读 0评论2011-10-17 niexining
分类:Python/Ruby

10进制的,纯属代码样例,不能当钟表,呵呵

  1. #coding: utf-8
  2. from Tkinter import *
  3. from math import sin, cos, pi
  4. WIDTH = 600
  5. HEIGHT = 600
  6. CENTER = (WIDTH/2,HEIGHT/2)
  7. RADIUS = 150
  8. POLY = 10

  9. FRAMES_PER_SEC = 1

  10. root = Tk()
  11. root.title('clock-computer')
  12. graph = Canvas(root, width=WIDTH, height=HEIGHT, background='white')
  13. graph.create_oval((CENTER[0]-RADIUS, CENTER[1]-RADIUS,CENTER[0]+RADIUS,CENTER[1]+RADIUS),outline='blue',width=2)

  14. TIMER = 0
  15. def update():
  16.     global TIMER
  17.     TIMER = (TIMER+1)%POLY**3
  18.     i,j,k = TIMER%POLY,TIMER/POLY,TIMER/POLY**2
  19.     graph.coords(S,CENTER+ (CENTER[0]+sin(2*pi*i/POLY)*130,CENTER[1]-cos(2*pi*i/POLY)*130))
  20.     graph.coords(M,CENTER+(CENTER[0]+sin(2*pi*j/POLY)*100,CENTER[1]-cos(2*pi*j/POLY)*100))
  21.     graph.coords(H,CENTER+(CENTER[0]+sin(2*pi*k/POLY)*70,CENTER[1]-cos(2*pi*k/POLY)*70))
  22.     graph.after(1000 / FRAMES_PER_SEC, update)

  23. for i in xrange(POLY):
  24.   graph.create_text((CENTER[0]+sin(2*pi*i/POLY)*(RADIUS-10),CENTER[1]-cos(2*pi*i/POLY)*(RADIUS-10)),text=i)
  25. o=graph.create_text(CENTER,text='Lambda')
  26. H=graph.create_line(CENTER+(CENTER[0],CENTER[1]-70),fill='black',width=3)
  27. M=graph.create_line(CENTER+(CENTER[0],CENTER[1]-100),fill='brown',width=2)
  28. S=graph.create_line(CENTER+(CENTER[0],CENTER[1]-130),fill='red',width=1)
  29. graph.after(1000 / FRAMES_PER_SEC, update)
  30. graph.pack()

  31. root.mainloop()
上一篇:背包问题的递归算法
下一篇:/root/autotest/client/tests/kvm/control