发布于2019-08-20 11:34 阅读(1155) 评论(0) 点赞(17) 收藏(3)
使用turtle库,time库自动绘制七段数码管,显示当前日期
#画笔粗细2.5,绘制结束隐藏画笔,线段间隔3/6,导入时间模块,手动输入日期改为自动获取日期
import turtle as t
import time
#定义画线or不画线函数
def DrawLine(draw):
t.pu()
t.fd(3)
t.pd()
t.pd() if draw else t.pu()
t.fd(40)
t.pu()
t.fd(3)
t.pd()
t.right(90)
#定义绘制函数
def DrawDigit(digit):
DrawLine(True) if digit in (2,3,4,5,6,8,9) else DrawLine(False)
DrawLine(True) if digit in (0,1,3,4,6,7,8,9) else DrawLine(False)
DrawLine(True) if digit in (0,2,3,5,6,8,9) else DrawLine(False)
DrawLine(True) if digit in (0,2,6,8) else DrawLine(False)
t.left(90)
DrawLine(True) if digit in (0,4,6,8,9) else DrawLine(False)
DrawLine(True) if digit in (0,2,3,5,6,7,8,9) else DrawLine(False)
DrawLine(True) if digit in (0,1,2,3,4,7,8,9) else DrawLine(False)
t.pu()
t.left(180)
t.fd(20)
#定义年月日输出函数
def write_data(s):
t.color((255,177,77))
t.write(s,font=("C:\\windows:\\font:\\msyh.ttl","10"))
t.pu()
t.fd(20)
t.pd()
t.color((89,89,89))
#获取时间数据
#定义绘制函数
def Draw(data):
for digit in data:
if digit == '-':
write_data("年")
elif digit == '=':
write_data("月")
elif digit == '+':
write_data("日")
else:
digit=eval(digit)
DrawDigit(digit)
t.hideturtle()
t.done()
#定义主函数
def main():
t.pensize(2.5)
t.pu()
t.goto(-300,0)
t.colormode(255)
t.color((89,89,89))
#引入时间
Draw(time.strftime('%Y-%m-%d+',time.gmtime()))
#调用主函数
main()
作者:comeonbady
链接:https://www.pythonheidong.com/blog/article/49094/ef9c805e8944bb3267d8/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!