首页 > 编程语言 >Python7段数码管绘制

Python7段数码管绘制

时间:2022-12-08 17:57:22浏览次数:37  
标签:digit False drawLine True else 数码管 fd Python7 绘制

#七段数码管绘制
import turtle as t
import time as T
def drawGap(): #绘制数码管的间隔
t.penup()
t.fd(5)
def drawLine(draw): #绘制单段数码管,draw为True时,则实画
drawGap();
t.pendown() if draw else t.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) #换个位置输出下一个字符,间隔
def drawDate(s):
t.pencolor('red')
for i in s:
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()把字符转换成单个数字
def main():
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()

 

 

 

标签:digit,False,drawLine,True,else,数码管,fd,Python7,绘制
From: https://www.cnblogs.com/123lujian/p/16966841.html

相关文章

  • Python 7段数码管绘制
    #七段数码管绘制importturtleastimporttimeasTdefdrawGap():#绘制数码管的间隔t.penup()t.fd(5)defdrawLine(draw):#绘制单段数码管,draw为True时,则实......
  • 7段数码管绘制
    代码如下: 1importturtle,datetime23defdrawGap():#绘制数码管间隔4turtle.penup()5turtle.fd(5)67defdrawLine(draw):#绘制单......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown(......
  • 数码管绘制时间
    1importturtle2importdatetime34defdrawGap():#绘制数码管间隔5turtle.penup()6turtle.fd(1)78defdrawLine(draw):#绘制单段数......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.pendown......
  • 7段数码管绘制
    importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()turtle.p......
  • 七段数码管控绘制
    代码如下:importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管drawGap()......
  • 7段数码管绘制python实验
    实验代码如下:1importturtle,time2defdrawGap():3turtle.penup()4turtle.fd(5)5defdrawLine(draw):#绘制单段数码管6drawGap()......
  • 7段数码管绘制 (2022年12月8日 14点38分)
    """7段数码管绘制"""importturtle,datetimedefdrawGap():#绘制数码管间隔turtle.penup()turtle.fd(5)defdrawLine(draw):#绘制单段数码管d......
  • 010.绘制后台首页UI布局
    1.index.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>慕课网办公OA系统</title><!--引入样式--><linkrel="style......