Import Turtle #画画库
Import Time #时间库
Def drawgap (): #每个数码管距离, imaging digital tube
Turtle.penup ()
TURTLE.FD (5)
def drawLine (draw): #单个数码管
Drawgap ()
Turtle.pendown () If draw else Turtle.penup () #如果是真, down, if false on up
TURTLE.FD (40)
Drawgap ()
Turtle.right (90)
def drawdigit (digit): #根据当前数字画几段数码管
DrawLine (True) if digit in [2,3,4,5,6,8,9] else DrawLine (False) #对123456 ... Digital Tube Planning
DrawLine (True) if digit in [0,1,3,4,5,6,7,8,9] else DrawLine (False)
DrawLine (True) if digit in [0,2,3,5,6,8,9] else DrawLine (False)
DrawLine (True) if digit in [0,2,6,8] else DrawLine (False)
Turtle.left (#这里不需要右拐), so add a left turn
DrawLine (True) if digit in [4,5,6,8,9,0] else DrawLine (False)
DrawLine (True) if digit in [2,3,5,6,7,8,9,0] else DrawLine (False)
DrawLine (True) if digit in [1,2,3,4,7,8,9,0] else DrawLine (False)
Turtle.left (#方向往右)
Turtle.penup () #提笔
TURTLE.FD (#移动)
def drawdate (date): #开始画时间
Turtle.pencolor (' Red ') #先直接把画笔染成红色
For I in Date:
if i = = '-': #如果是-
Turtle.write (' Year ', font= (' Arial ', ' normal ')) #那就画年
Turtle.pencolor (' green ')
TURTLE.FD (40)
elif i = = ' = ': #如果是 =
Turtle.write (' Month ', font= (' Arial ', ' normal ')) #那就画月
Turtle.pencolor (' Blue ')
TURTLE.FD (40)
elif i = = ' + ': #如果是 +
Turtle.write (' Day ', font= (' Arial ', ' normal ')) #那就画日
Else
Drawdigit (eval (i)) #不然正常画数码管
def main ():
Turtle.setup (800,350,200,200) #画布大小
Turtle.penup ()
TURTLE.FD (-300)
Turtle.pensize (5)
Drawdate (Time.strftime ('%y-%m=%d+ ', Time.gmtime ())) #用gmtime获取当前时间, format into-=+ format, and then place it in Drawdate ()
Turtle.hideturtle ()
Turtle.done ()
Main ()
The whole process in plagiarism, too difficult!
Study hard and keep up!
"Python" Seven digital tube date