能,即每秒刷新一次。
实现代码如下:
from turtle import * from datetime import datetime import time def drawGap(): penup() fd(5) def drawLine(draw): drawGap() pendown() if draw else penup() fd(40) drawGap() right(90) def drawDigit(d): speed(50) drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False) drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,2,6,8] else drawLine(False) left(90) drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False) drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False) left(180) penup() fd(20) def drawDate(date): pencolor('Red') for i in date: if i=="-": write('时',font=('Arial',24,'normal')) pencolor('Green') fd(40) elif i=='=': write('分', font=('Arial', 24, 'normal')) pencolor('Blue') fd(40) elif i=='+': write('秒', font=('Arial', 24, 'normal')) else: drawDigit(eval(i)) def main(): setup(800,350,200,200) while True: reset() penup() fd(-300) pensize(8) tracer(False) hideturtle() drawDate(datetime.now().strftime('%H-%M=%S+')) time.sleep(1) done() main()
运行效果如图: