程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

python七段数码管,turtle和time实现

发布于2019-08-20 11:34     阅读(1196)     评论(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()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68


所属网站分类: 技术文章 > 博客

作者:comeonbady

链接:https://www.pythonheidong.com/blog/article/49094/ef9c805e8944bb3267d8/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

17 0
收藏该文
已收藏

评论内容:(最多支持255个字符)