# 数码管
显示系统年,月,日,时间
1 import turtle,datetime 2 def drawling(draw): 3 4 turtle.pendown() if draw else turtle.penup() 5 turtle.fd(40) 6 turtle.right(90) 7 8 def draworigin(d): 9 drawling (True) if d in [2,3,4,5,6,8,9] else drawling (False) 10 drawling (True) if d in [0,1,3,4,5,6,7,8,9,'A','b','d'] else drawling (False) 11 drawling (True) if d in [0,2,3,5,6,8,'b','b','E'] else drawling (False) 12 drawling (True) if d in [0,2,6,8,'A','b','C','d','E','F'] else drawling (False) 13 14 turtle.left(90) 15 drawling (True) if d in [0,4,5,6,8,9,'A','b','C','E','F'] else drawling (False) 16 drawling (True) if d in [0,2,3,5,6,7,8,9,'A','C','E','F'] else drawling (False) 17 drawling (True) if d in [0,1,2,3,4,7,8,9,'A','d','E','F'] else drawling (False) 18 turtle.left(180) 19 turtle.penup() 20 turtle.fd(20) 21 def drawdate(date): 22 turtle.pencolor("aquamarine2") 23 for I in date: 24 if I == '-': 25 turtle.write("年", font=("Arial", 18, "normal")) 26 turtle.pencolor("pale green") 27 turtle.fd(40) 28 elif I == '=': 29 turtle.write("月", font=("Arial", 18, "normal")) 30 turtle.pencolor("spring green") 31 turtle.fd(40) 32 elif I == '+': 33 turtle.write("日", font=("Arial", 18, "normal")) 34 turtle.pencolor("green yellow") 35 turtle.fd(40) 36 elif I == '*': 37 turtle.write("时", font=("Arial", 18, "normal")) 38 turtle.pencolor("cyan") 39 turtle.fd(40) 40 else: 41 draworigin(eval(I)) 42 43 44 45 def main(): 46 turtle.setup(1000,450,200,200) 47 turtle.penup() 48 turtle.pensize(7) 49 turtle.speed("fast") 50 turtle.fd(-400) 51 turtle.pendown() 52 drawdate(datetime.datetime.now().strftime("%Y-%m=%d+%H*")) 53 54 main() 55 turtle.done()
运行结果
21:52:40
干员:XinJi[21][1][41]
42
标签:turtle,False,drawling,40,else,数码管,True From: https://www.cnblogs.com/Calinio/p/17845016.html