Python基于turtle海龟画板的"七段数码管绘制显示日历"项目 |
您所在的位置:网站首页 › python海龟画画垃圾分类 › Python基于turtle海龟画板的"七段数码管绘制显示日历"项目 |
项目大致需求:利用turtle画板画出当前时间(年月日),如下图: 绘制单个数码管: 对于本项目来说,我是按照下图中1-7-6-5-4-3-2这样的顺序来的,当然你也可以自己调整。 气死我了,上代码😂😂😂: # @Time : 2020/4/6 # @File : Chap03.py # @Title : "七段数码管绘制" 项目 # @Software: PyCharm import turtle as t import time t.setup(width=1.0,height=1.0) t.pensize(5) t.pencolor('red') t.speed(8) t.up() t.bk(700) t.down() #drawline()函数会绘制显示的数码管 def drawline(): t.up() t.fd(10) t.down() t.fd(60) t.up() t.fd(10) t.down() #drawnoline()函数会绘制不显示的数码管(也就是提笔,向前一段距离再落笔,并没有留下痕迹) def drawnoline(): t.up() t.fd(80) t.down() #drawword()函数绘制对应的汉字,年月日时分秒,同时会重新设置画笔颜色位置等 def drawword(word,color="red"): t.up() t.fd(20) t.down() t.write(word,font=("Courier",14,"bold")) t.pencolor(color) t.up() t.fd(40) t.down() #获取当前系统时间 time=time.localtime() #timelist是当前时间全部数字的列表 timelist=list(str(time.tm_year)+str(time.tm_mon)+str(time.tm_mday)+str(time.tm_hour)+str(time.tm_min)) year_len=len(str(time.tm_year)) mon_len=len(str(time.tm_mon)) day_len=len(str(time.tm_mday)) hour_len=len(str(time.tm_hour)) min_len=len(str(time.tm_min)) write_len=0 #这里定义的字典代表每个数字显示的是哪几段数码管,不显示的数码管字母就不在对应的值中 dict={'0':['b','c','d','e','f','g'], '1':['b','g'], '2':['a','b','c','e','f'], '3':['a','b','c','f','g'], '4':['a','b','d','g'], '5':['a','c','d','f','g'], '6':['a','c','d','e','f','g'], '7':['b','c','g'], '8':['a','b','c','d','e','f','g'], '9':['a','b','c','d','f','g']} for item in timelist: list=dict.get(item,"False") print("list={}".format(list)) for i in range(97, 104): if chr(i) in list: print(chr(i)+" zai") drawline() if chr(i)!='d': t.left(90) continue else: print(chr(i)+" buzai") drawnoline() if chr(i) != 'd': t.left(90) continue t.seth(0) t.up() t.fd(20) t.down write_len=write_len+1 if write_len == year_len: drawword("年",color="blue") if write_len == year_len+mon_len: drawword("月",color="green") if write_len == year_len+mon_len+day_len: drawword("日",color="orange") if write_len == year_len + mon_len+day_len+hour_len: drawword("时",color="purple") if write_len == year_len + mon_len+day_len+hour_len+min_len: drawword("分") t.hideturtle() t.done()最终运行结果如下图: |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |