Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157242
  • 博文数量: 33
  • 博客积分: 2057
  • 博客等级: 大尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-19 16:37
文章分类
文章存档

2013年(2)

2012年(23)

2011年(8)

分类: Python/Ruby

2011-10-17 23:51:02

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()
阅读(1904) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~