• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
汤圆喵喵
博客园    首页    新随笔    联系   管理    订阅  订阅
七段数码管绘制(时、分、秒)
import turtle as t
import time
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(("black"))
            t.fd(60)
        elif i == '/':
            t.write('分',font=("宋体", 30, "normal"))
            t.pencolor("orange")
            t.fd(60)
        elif i == '!':
            t.write('秒',font=("宋体", 30, "normal"))
        else:
            popstart(eval(i))
def main():
    t.setup(800, 700, 200,200)
    t.penup()
    t.fd(-350)
    t.pensize(4)
    popdate(time.strftime('%H*%M/%S!',time.localtime()))
    t.hideturtle()
main()

 

 

 

posted on 2020-10-17 18:48  汤圆喵喵  阅读(367)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3