import turtle import datetime import time def draw_gap(): # 画数码间隔 turtle.penup() turtle.fd(5) def draw_line(draw): # 画单段数码管 draw_gap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) draw_gap() turtle.right(90) def draw_digit(d): # 根据数字绘制七段数码管 draw_line(True) if d in [2, 3, 4, 5, 6, 8, 9] else draw_line(False) draw_line(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else draw_line(False) draw_line(True) if d in [0, 2, 3, 5, 6, 8, 9] else draw_line(False) draw_line(True) if d in [0, 2, 6, 8] else draw_line(False) turtle.left(90) draw_line(True) if d in [0, 4, 5, 6, 8, 9] else draw_line(False) draw_line(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else draw_line(False) draw_line(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else draw_line(False) turtle.left(180) turtle.penup() turtle.fd(20) def draw_date(date): turtle.pencolor("pink") for i in date: if i == '-': turtle.write('年', font=("Arial", 18, "normal")) turtle.pencolor("skyblue") turtle.fd(40) elif i == '=': turtle.write('月', font=("Arial", 18, "normal")) turtle.pencolor("purple") turtle.fd(40) elif i == '+': turtle.write('日', font=("Arial", 18, "normal")) turtle.pencolor("blue") turtle.fd(40) elif i == '$': turtle.write('时', font=("Arial", 18, "normal")) turtle.pencolor("gold") turtle.fd(40) elif i == '#': turtle.write('分', font=("Arial", 18, "normal")) turtle.fd(40) else: draw_digit(eval(i)) def again(s): turtle.speed(0) turtle.penup() turtle.fd(-550) turtle.pensize(5) draw_date(datetime.datetime.now().strftime('%Y-%m=%d+%H$%M#')) time.sleep(0.5) turtle.reset() turtle.hideturtle def main(): turtle.setup(1200, 550, 100, 100) again(6) main() turtle.done()