《2018年5月13日》【连续214天】
标题:七段数码管的绘制和 PyInstaller库;
内容:
A.PyInstaller:
第三方库:通过pip工具安装:在cmd界面:pip installer pyinstaller
-h 查看帮助
--clean 清理打包过程中的临时文件
-D , --onedir 默认值,生成dist文件夹
-F ,--onefile 在dist文件夹中只生成独立的打包文件;
-i <图标文件名.ico> 指定打包程序使用的图标(icon)文件
B.七段数码管绘制:
#SevenDigitsDrawV2.py
import turtle as t
import time as ti
def drawGap(): #绘制数码管间隔
t.pu()
t.fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
t.pd() if draw else t.pu()
t.fd(40)
drawGap()
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,5,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,5,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.lt(180)
t.pu() #后续的数字
t.fd(20)
def drawDate(date): #data为日期,格式为'%Y-%m=%d+'
t.pencolor('red')
for i in date:
if i =='-':
t.write('年',font=("Arial",18,"normal"))
t.pencolor("green")
t.fd(40)
elif i =='=':
t.write('月',font=("Arial",18,"normal"))
t.pencolor("blue")
t.fd(40)
elif i=='+':
t.write('日',font=("Arial",18,"normal"))
else:
drawDigit(eval(i))
def main():
t.setup(800,350,200,200)
t.pu()
t.fd(-300)
t.pensize(5)
drawDate(ti.strftime('%Y-%m=%d+',ti.gmtime()))
t.hideturtle()
t.done()
main()
效果如图: