Python编写时间显示程序,要求时钟程序每秒钟刷新一次
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python编写时间显示程序,要求时钟程序每秒钟刷新一次,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2629字,纯文字阅读大概需要4分钟。
内容图文
![Python编写时间显示程序,要求时钟程序每秒钟刷新一次](/upload/InfoBanner/zyjiaocheng/611/26eec732785d4c41bee6c517f17d1e94.jpg)
数码管显示时间,动态刷新
- 运行截图
- 源代码
from turtle import * #导入turtle包
from datetime import datetime
import time
def drawLine(draw, length): # 绘制单段数码管
if (draw): #if函数,绘制六边形路径
pendown()
begin_fill() #开始填充
left(45)
fd(int(length / 10.0 * (2 ** 0.5))) #前进步数,int()把数值转化成整数
right(45)
fd(int(length * 8 / 10.0))
right(45)
fd(int(length / 10.0 * (2 ** 0.5)))
right(90)
fd(int(length / 10.0 * (2 ** 0.5)))
right(45)
fd(int(length * 8 / 10.0))
right(45)
fd(int(length / 10.0 * (2 ** 0.5)))
right(135)
end_fill() #结束填充
penup()
fd(length)
right(90)
def drawDigit(digit, length): # 根据数字绘制七段数码管,声明函数drawDigit带有两个参数
drawLine(True, length) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False, length) #如果参数digit在列表中,调用drawLine函数参数draw为True,并把参数length传给drawLine函数
drawLine(True, length) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False, length)
drawLine(True, length) if digit in [0, 2, 3, 5, 6, 8, 9] else drawLine(False, length)
drawLine(True, length) if digit in [0, 2, 6, 8] else drawLine(False, length)
left(90)
drawLine(True, length) if digit in [0, 4, 5, 6, 8, 9] else drawLine(False, length)
drawLine(True, length) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False, length)
drawLine(True, length) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False, length)
left(180)
penup()
fd(20)
def drawDay(day): #获取要输出的数字
for i in day:
if i == '-':
#write('年', font=('Arial', 18, 'normal'))
fd(30)
pendown()
pencolor('blue')
fd(20)
penup()
fd(30)
pendown()
pencolor('#dc6016')
elif i == '=':
#write('月', font=('Arial', 18, 'normal'))
fd(30)
pendown()
pencolor('blue')
fd(20)
penup()
fd(30)
pendown()
pencolor('#fba819')
elif i == '+':
#write('日', font=('Arial', 18, 'normal'))
pencolor('#fbc819')
fd(60)
elif i == '*':
#write('时', font=('Arial', 18, 'normal'))
pencolor('blue')
fd(30)
right(90)
penup()
fd(10)
pendown()
fd(20)
penup()
left(180)
fd(40)
pendown()
fd(20)
right(180)
fd(30)
penup()
left(90)
pencolor('#e56526')
fd(30)
elif i == '#':
#write('分', font=('Arial', 18, 'normal'))
pencolor('blue')
fd(30)
right(90)
penup()
fd(10)
pendown()
fd(20)
penup()
left(180)
fd(40)
pendown()
fd(20)
right(180)
fd(30)
penup()
left(90)
fd(30)
pencolor('purple')
elif i == '?':
write(' ')
fd(60)
else:
drawDigit(eval(i),30)
def main(): #main主函数
setup(1500,350,200,200)
fd(-600)
pensize(5)
hideturtle() # 隐藏海龟
while True:
tracer(False) #加快作图,一次性画好
penup()
goto(-600, 0)
color('red', 'yellow')
drawDay(datetime.now().strftime('%Y-%m=%d+%H*%M#%S?')) #调用drawData函数,获得要输出的数字串
time.sleep(1)
clear() #清屏
done()
main() #执行main函数
如果对您解决问题有所帮助,点个赞支持下小博叭
内容总结
以上是互联网集市为您收集整理的Python编写时间显示程序,要求时钟程序每秒钟刷新一次全部内容,希望文章能够帮你解决Python编写时间显示程序,要求时钟程序每秒钟刷新一次所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。