7段数码管绘制

要求:画出,系统时间。具体包括:小时,分,秒,星期。 

import turtle as t
import time
a = time.strftime('%a',time.localtime())
if a=='Mon':
    c = 1
elif a == 'Tue':
    c =2
elif a == 'Wed':
    c =3
elif a =='Thu':
    c =4
elif a == 'Fri':
    c =5
elif a == 'Sat':
    c =6
elif a == 'Sun':
    c == 7
def popspace(): #单管间隔
    t.penup()
    t.fd(4)
def popline(draw):   #画数码管
    popspace()
    t.pendown() if draw else t.penup()
    t.fd(40)
    popspace()
    t.right(90)
def popstart(d): #画数字数码管
    popline(True) if d in [2,3,4,5,6,8,9] else popline(False)
    popline(True) if d in [0,1,3,4,5,6,7,8,9] else popline(False)
    popline(True) if d in [0,2,3,5,6,8,9] else popline(False)
    popline(True) if d in [0,2,6,8] else popline(False)
    t.left(90)
    popline(True) if d in [0,4,5,6,8,9] else popline(False)
    popline(True) if d in [0,2,3,5,6,7,8,9] else popline(False)
    popline(True) if d in [0,1,2,3,4,7,8,9] else popline(False)
    t.left(180)
    t.penup()
    t.fd(30)
def popdate(date):
    t.pencolor("red")
    for i in date:
        if i == '*':
            t.write('',font=("宋体", 30, "normal"))
            t.pencolor(("green"))
            t.fd(60)
        elif i == '/':
            t.write('',font=("宋体", 30, "normal"))
            t.pencolor("orange")
            t.fd(60)
        elif i == '!':
            t.write('',font=("宋体", 30, "normal"))
            t.pencolor("pink")
            t.fd(60)
        elif i == '-':
            t.write('星期 ',font=("宋体", 30, "normal"))
            t.fd(60)
        else:
            popstart(eval(i))
def main():
    t.setup(900, 700, 200,200)
    t.penup()
    t.fd(-350)
    t.pensize(4)
    popdate(time.strftime('%H*%M/%S!-c',time.localtime()))
    t.hideturtle()
main()

运行结果

 

posted @ 2023-11-20 23:42  Sco-c1116  阅读(46)  评论(0)    收藏  举报