首页 > 其他分享 >第五次测试 7段数码管绘制

第五次测试 7段数码管绘制

时间:2022-12-08 20:12:51浏览次数:39  
标签:cur drawLine tt else 数码管 第五次 fd time 绘制

7段数码管绘制

        请画出,系统时间。具体包括:年,月,日,小时,分,秒

代码如下:

# coding:utf-8
# 绘制七段数码管,显示当前时间
import time
import turtle as tt


# 绘制间隔
def drawGap():
    tt.penup()
    tt.fd(5)


# 绘制单段数码管
def drawLine(draw):
    drawGap()

    if (draw):
        tt.pendown()
    else:
        tt.penup()

    tt.fd(50)
    drawGap()
    tt.right(90)


# 绘制当前时间
def drawDate(date):
    tt.pencolor("red")
    for i in date:
        if i == '+':
            tt.write("年", font=("黑体", 25, "normal"))
            tt.pencolor("green")
            tt.fd(50)
        elif i == '-':
            tt.write("月", font=("黑体", 25, "normal"))
            tt.pencolor("blue")
            tt.fd(50)
        elif i == '*':
            tt.write("日", font=("黑体", 25, "normal"))
            tt.pencolor("purple")
            tt.fd(50)
        elif i == '=':
            tt.write("时", font=("黑体", 25, "normal"))
            tt.pencolor("yellow")
            tt.fd(50)
        elif i == '#':
            tt.write("分", font=("黑体", 25, "normal"))
            tt.pencolor("black")
            tt.fd(50)
        elif i == '$':
            tt.write("秒", font=("黑体", 25, "normal"))

        else:
            drawDigit(eval(i))


# 绘制数码管
def drawDigit(cur_time):
    if cur_time in [2, 3, 4, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    if cur_time in [0, 1, 3, 4, 5, 6, 7, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    if cur_time in [0, 2, 3, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    if cur_time in [0, 2, 6, 8]:
        drawLine(True)
    else:
        drawLine(False)

    tt.left(90)

    if cur_time in [0, 4, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    if cur_time in [0, 2, 3, 5, 6, 7, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    if cur_time in [0, 1, 2, 3, 4, 7, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    tt.left(180)
    tt.penup()
    tt.fd(20)


# 主函数
def main():
    tt.setup(1600, 300, 200, 200)
    tt.penup()
    tt.fd(-730)
    tt.pensize(5)
    drawDate(time.strftime('%Y+%m-%d*%H=%M#%S$', time.localtime()))
    tt.hideturtle()
    tt.done()


if __name__ == "__main__":
    main()

结果如下:

 

标签:cur,drawLine,tt,else,数码管,第五次,fd,time,绘制
From: https://www.cnblogs.com/diana77/p/16967143.html

相关文章

  • 7段数码管绘制
    """7段数码管绘制"""importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap(......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():turtle.penup()turtle.fd(5)defdrawLine(draw):drawGap()turtle.pendown()ifdrawelseturtle.penup(......
  • 7段数码管绘制
    #绘制七段数码管importturtleastimporttimedefdrawGap():#绘制数码管间隔的函数t.penup()t.fd(5)defdrawLine(draw):#单个线段的......
  • Python7段数码管绘制
    #七段数码管绘制importturtleastimporttimeasTdefdrawGap():#绘制数码管的间隔t.penup()t.fd(5)defdrawLine(draw):#绘制单段数码管,draw为True时,则实......
  • Python 7段数码管绘制
    #七段数码管绘制importturtleastimporttimeasTdefdrawGap():#绘制数码管的间隔t.penup()t.fd(5)defdrawLine(draw):#绘制单段数码管,draw为True时,则实......
  • 7段数码管绘制
    代码如下: 1importturtle,datetime23defdrawGap():#绘制数码管间隔4turtle.penup()5turtle.fd(5)67defdrawLine(draw):#绘制单......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown(......
  • 数码管绘制时间
    1importturtle2importdatetime34defdrawGap():#绘制数码管间隔5turtle.penup()6turtle.fd(1)78defdrawLine(draw):#绘制单段数......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.p......