由于chrome装了很多插件,没打开几个页面内存就“喝高”了。改用opera,并安装了个binary clock,蛮好玩的。刚写了下,总结之.
#-*- coding:UTF-8 -*-
from Tkinter import *
import time
class ClockCanvas(Canvas):
def __init__(self, parent):
Canvas.__init__(self, parent, bg='white')
self.pack()
#
self.nPos_x, self.nPos_y = 30, 40 # 起始点
self.nLength_x, self.nLength_y = 30,30 # 矩形长宽
self.nSpan = 10 # 相邻的距离
#
self.rectID = [] # 控件ID列表
#
self.DrawClock()
self.run()
def DrawClock(self):
for row in xrange(4):
for col in xrange(3):
#
firstPos_x = self.nPos_x + self.nLength_x*(col*3) + self.nSpan*(col*3)
firstPos_y = self.nPos_y + self.nLength_y*row + self.nSpan*row
#
secondPos_x = firstPos_x + self.nLength_x + self.nSpan
secondPos_y = firstPos_y
# first
if col == 0 and row in (0,1):
self.rectID.append(0) # for easy to map after
else:
self.rectID.append(self.create_rectangle(firstPos_x , firstPos_y, firstPos_x + self.nLength_x, firstPos_y + self.nLength_y, fill='gray'))
# second
self.rectID.append(self.create_rectangle(secondPos_x, secondPos_y, secondPos_x + self.nLength_x, secondPos_y + self.nLength_y, fill='gray'))
def run(self):
nTime = time.localtime(time.time())
nHour = nTime.tm_hour
nMinute = nTime.tm_min
nSecond = nTime.tm_sec
timeList = [nHour / 10, nHour % 10,
nMinute / 10, nMinute % 10,
nSecond / 10, nSecond % 10]
judgement = 16
for row in xrange(4):
judgement >>= 1
for col in xrange(6):
if col == 0 and row in (0,1):
pass
else:
#
nResult = timeList[col] & judgement
if nResult:
self.itemconfig(self.rectID[col+row*6], fill='blue')
else:
self.itemconfig(self.rectID[col+row*6], fill='gray')
self.after(250, self.run)
root = Tk()
root.title('Binary Clock')
ClockCanvas(root)
root.mainloop()
效果: