猫史档案馆


【Python作品分享】时间【求助帖】

用户:原力开发原力开发查看:0 回复:0 评论:0 创建时间:2022-03-24T21:24:39


【作品展示】

center_image

 

【作品介绍】

它显示的是现在时间

 

【作品源代码】

import turtle
import turtle as t
import time


t.pensize(5)
t.tracer(0, 0)
t.shape("turtle")
t.ht()
num_dict = {0: [1, 1, 1, 1, 1, 1, 0], 1: [0, 0, 1, 1, 0, 0, 0], 2: [0, 1, 1, 0, 1, 1, 1], 3: [0, 1, 1, 1, 1, 0, 1], 4: [1, 0, 1, 1, 0, 0, 1], 5: [1, 1, 0, 1, 1, 0, 1], 6: [1, 1, 0, 1, 1, 1, 1], 7: [0, 1, 1, 1, 0, 0, 0], 8: [1, 1, 1, 1, 1, 1, 1], 9: [1, 1, 1, 1, 1, 0, 1]}

def line(down):

    t.penup()
    t.forward(10)
    if (down == 1):
        t.pendown()
    t.forward(80)
    t.penup()
    t.forward(10)

def draw_num(n, x, y):

    t.penup()
    t.goto(x, y)
    t.setheading(90)
    count = 0
    for i in num_dict[n]:
        line(i)
        if (count in [0, 1, 3, 4, 5]):
            t.right(90)
        count += 1

def draw_colon(x, y):

    t.penup()
    t.goto(x, y)
    t.left(90)
    t.forward(50)
    t.stamp()
    t.backward(100)
    t.stamp()
    t.forward(50)
    t.right(90)

while True:
    x = (-445)
    y = 130
    time_str = time.strftime('%H:%M:%S')
    for c in time_str:
        if (c != ':'):
            draw_num(int(c), x, y)
            x += 130
        else:
            x += 20
            draw_colon(x, y)
            x += 50
    t.update()
    t.clear()

turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页