python七段数码管绘制单个数字_#Python语言程序设计Demo - 七段数码管绘制
#七段數碼管繪制
importturtle as timporttime as Tdef drawGap(): #繪制數碼管的間隔
t.penup()
t.fd(5)def drawLine(draw): #繪制單段數碼管,draw為True時,則實畫
drawGap();
t.pendown()if draw elset.penup()
t.fd(40)
drawGap();
t.right(90)def drawDigit(digit): #根據數字繪制七段數碼管:如下七段: 1,2,3,4,5,6,7
drawLine(True) if digit not in [0,1,7] else drawLine(False) #1
drawLine(True) if digit not in [2 ] else drawLine(False) #2
drawLine(True) if digit not in [1,4,7] else drawLine(False) #3
drawLine(True) if digit not in [1,3,4,5,7,9] else drawLine(False) #4
t.left(90)
drawLine(True)if digit not in [1,2,3,7] else drawLine(False) #5
drawLine(True) if digit not in [4,1] else drawLine(False) #6
drawLine(True) if digit not in [5,6] else drawLine(False) #7
t.left(180);t.penup();
t.fd(10) #換個位置輸出下一個字符,間隔
defdrawDate(s):
t.pencolor('red')for i ins:if i=='-':
t.write('年',font=('Arial',18,'normal'))
t.pencolor('green')
t.fd(30)elif i=='=':
t.write('月',font=('Arial',18,'normal'))
t.pencolor('blue')
t.fd(30)elif i=='+':
t.write('日', font=('Arial', 18, 'normal'))
t.fd(30)else:
drawDigit(eval(i))#通過eval()把字符轉換成單個數字
defmain():
t.setup(800,400)
t.penup()
t.fd(-300) #將起點挪到畫布的左邊
t.pensize(6)
drawDate(T.strftime('%Y-%m=%d+',T.gmtime()))#drawDate('0123456789')
t.hideturtle() #隱藏畫筆的形狀
t.done()
main()
總結
以上是生活随笔為你收集整理的python七段数码管绘制单个数字_#Python语言程序设计Demo - 七段数码管绘制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: scatter python_pytho
- 下一篇: C语言自定义函数(图文详解)(循环队列及