Python绘制七段数码管显示当前时间
2018-05-01 17:14
429 查看
版权声明:个人博客网站:https://cunyu1943.github.io/, 欢迎访问留言交流! https://blog.csdn.net/github_39655029/article/details/80157786
利用Python中的turtle图形库绘制七段数码管,显示当前时间
代码
# coding:utf-8 # 绘制七段数码管,显示当前时间 import time import turtle as tt # 绘制间隔 def drawGap(): tt.penup() tt.fd(5) # 绘制单段数码管 def drawLine(draw): drawGap() if(draw): tt.pendown() else: tt.penup() tt.fd(50) drawGap() tt.right(90) # 绘制当前时间 def drawDate(date): tt.pencolor("red") for i in date: if i == '+': tt.write("年", font = ("黑体", 25, "normal")) tt.pencolor("green") tt.fd(50) elif i == '-': tt.write("月", font=("黑体", 25, "normal")) tt.pencolor("blue") tt.fd(50) elif i == '*': tt.write("日", font=("黑体", 25, "normal")) tt.pencolor("purple") tt.fd(50) elif i == '=': tt.write("时", font=("黑体", 25, "normal")) tt.pencolor("yellow") tt.fd(50) elif i == '#': tt.write("分", font=("黑体", 25, "normal")) tt.pencolor("black") tt.fd(50) elif i == '$': tt.write("秒", font=("黑体", 25, "normal")) else: drawDigit(eval(i)) # 绘制数码管 def drawDigit(cur_time): if cur_time in [2, 3, 4, 5, 6, 8, 9]: drawLine(True) else: drawLine(False) if cur_time in [0, 1, 3, 4, 5, 6, 7, 8, 9]: drawLine(True) else: drawLine(False) if cur_time in [0, 2, 3, 5, 6, 8, 9]: drawLine(True) else: drawLine(False) if cur_time in [0, 2, 6, 8]: drawLine(True) else: drawLine(False) tt.left(90) if cur_time in [0, 4, 5, 6, 8, 9]: drawLine(True) else: drawLine(False) if cur_time in [0, 2, 3, 5, 6, 7, 8, 9]: drawLine(True) else: drawLine(False) if cur_time in [0, 1, 2, 3, 4, 7, 8, 9]: drawLine(True) else: drawLine(False) tt.left(180) tt.penup() tt.fd(20) # 主函数 def main(): tt.setup(1600, 300, 200, 200) tt.penup() tt.fd(-730) tt.pensize(5) drawDate(time.strftime('%Y+%m-%d*%H=%M#%S$', time.localtime())) tt.hideturtle() tt.done() if __name__ == "__main__": main()
结果
总结
通过在mooc网学习相关知识,借鉴相关代码,最终实现本次设计。
阅读更多相关文章推荐
- Python绘制数码管显示当前时间
- python +Django 搭建web开发环境初步,显示当前时间
- python学习之获取当前时间的方法(可以任意取时间的任何一个对象显示)
- 用GDI+绘制了一个钟表盘的类似物,显示当前的时间
- python +Django 搭建web开发环境初步,显示当前时间
- android cavas 绘制坐标系并显示矩形波方波-横轴为当前时间动态更新(不用achartengine)
- python +Django 搭建web开发环境初步,显示当前时间
- python显示当前时间
- tkinter显示当前时间 分类: python 2013-06-30 17:08 402人阅读 评论(0) 收藏
- python显示当前系统时间
- 绘制一个显示当前时间的StiilClock
- python获取当前时间和前一天时间
- mfc 单文档显示当前系统时间
- Python获取当前时间
- javascript 显示当前时间 练习01
- c#窗体编程之建立时钟程序显示当前时间
- asp.net 实现动态显示当前时间(不用javascript不考虑开销)
- 可以显示当前时间的JavaScript
- c# winForm 将窗体状态栏StatusStrip 分成左中右三部分 右边显示当前时间
- 使用js显示当前时间示例