Python钟表

今天,Python版钟表出炉啦!

代码:

import turtle as ttt
import time

t = ttt.Turtle()
t.hideturtle()
s = ttt.Turtle()
s.hideturtle()
s.left(90)
s.speed(0)
f = ttt.Turtle()
f.hideturtle()
f.left(90)
f.speed(0)
m = ttt.Turtle()
m.hideturtle()
m.left(90)
m.speed(0)

def draw_table():
    ttt.tracer(0)
    t.penup()
    t.seth(90)
    for i in range(12):
        t.right(360 / 12)
        t.forward(200)
        t.pendown()
        t.write(i + 1, align="center", font=("微软雅黑", 18, 'normal'))
        t.penup()
        t.backward(200)
    ttt.update()

def draw_time():
    
    localtime = time.localtime(time.time())
    global __hh
    __hh = localtime[3] % 12
    global __ff
    __ff = localtime[4]
    global __mm
    __mm = localtime[5]
    print(__hh, __ff, __mm)
    
    s.clear()
    s.seth(90)
    s.right((__hh+(__ff/60))*30)
    s.pensize(15)
    s.fd(60)
    s.fd(-60)
    ttt.update()
    
    f.clear()
    f.seth(90)
    f.right(__ff*6)
    f.pensize(7)
    f.fd(100)
    f.fd(-100)
    ttt.update()
    
    m.clear()
    m.seth(90)
    m.right(__mm*6)
    m.pensize(3)
    m.fd(170)
    m.fd(-170)
    ttt.update()
    
draw_table()

while True:
    time.sleep(0.99)
    draw_time()
    ttt.update()

完毕!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HellowZheng

老铁,您的打赏是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值