今天根据网上的教程修改了七段数码管的程序,引入了time库函数,这样程序可以
根据系统的时间画出七段数码管了。废话不多说了,直接上程序:
1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 #Segement7_2.py 4 import turtle,time 5 def drawGap(): 6 turtle.penup() 7 turtle.fd(5) 8 def drawline(draw): 9 drawGap() 10 turtle.pendown() if draw else turtle.penup() 11 turtle.fd(40) 12 drawGap() 13 turtle.right(90) 14 def drawdigit(digit): 15 drawline(True) if digit in [2,3,4,5,6,8,9] else drawline(False) 16 drawline(True) if digit in [0,1,3,4,5,6,7,8,9] else drawline(False) 17 drawline(True) if digit in [0,2,3,5,6,8,9] else drawline(False) 18 drawline(True) if digit in [0,2,6,8] else drawline(False) 19 turtle.left(90) 20 drawline(True) if digit in [0,4,5,6,8,9] else drawline(False) 21 drawline(True) if digit in [0,2,3,5,6,7,8,9] else drawline(False) 22 drawline(True) if digit in [0,1,2,3,4,7,8,9] else drawline(False) 23 turtle.left(180) 24 turtle.penup() 25 turtle.fd(20) 26 def drawdate(date): 27 turtle.pencolor("red") 28 for i in date: 29 if i=='-': 30 turtle.write("年",font=("Arial",18,"normal")) 31 turtle.pencolor("green") 32 turtle.fd(40) 33 elif i=='=': 34 turtle.write("月",font=("Arial",18,"normal")) 35 turtle.pencolor("blue") 36 turtle.fd(40) 37 elif i=='+': 38 turtle.write("日",font=("Arial",18,"normal")) 39 else: 40 drawdigit(eval(i)) 41 def main(): 42 turtle.setup(800,350,200,200) 43 turtle.penup() 44 turtle.fd(-300) 45 turtle.pensize(5) 46 drawdate(time.strftime("%Y-%m=%d+",time.gmtime())) 47 #drawdate('20181010') 48 turtle.hideturtle() 49 turtle.done() 50 main()
来源:https://www.cnblogs.com/xuelanga000/p/12651190.html