其他分享
首页 > 其他分享> > 7段数码管绘制

7段数码管绘制

作者:互联网

import turtle as t
import time
t.screensize(1000,600)
def go(x,y):
t.penup()
t.goto(x,y)
t.setheading(0)
t.pendown()
def write():
go(0,20)
t.pencolor('pink')
t.write('年',font=('YaHei',40,'bold'))
go(290,20)
t.pencolor('red')
t.write('月',font=('YaHei',40,'bold'))
t.pencolor('orange')
go(580,20)
t.write('日',font=('YaHei',40,'bold'))
t.pencolor('green')
go(0,-240)
t.write('时',font=('YaHei',40,'bold'))
t.tracer(False)
def mk():
t.begin_poly()
t.forward(100)
t.right(140)
t.forward(20)
t.right(40)
t.forward(69.35)
t.right(40)
t.forward(20)
t.end_poly()
t.clear()
def zc(name):
shape =t.get_poly()
t.register_shape(name,shape)
mk()
zc('a')
def szz(n,color,wt,x,y):
for i in range(10):
wt.penup()
wt.clear()
wt.goto(0+x,0+y)
wt.setheading(0)
wt.pendown()
wt.shape('a')
wt.color(color)
s1=wt.stamp()
wt.penup()
wt.goto(0+x,110+y)
wt.pendown()
s2=wt.stamp()
wt.penup()
wt.left(90)
wt.goto(-100+x,120+y)
wt.pendown()
s3=wt.stamp()
wt.penup()
wt.left(90)
wt.goto(-100+x,10+y)
wt.pendown()
s4=wt.stamp()
wt.penup()
wt.goto(-100+x,-100+y)
wt.pendown()
s5=wt.stamp()
wt.penup()
wt.left(90)
wt.goto(0+x,-110+y)
wt.pendown()
s6=wt.stamp()
wt.penup()
wt.backward(110)
wt.pendown()
s7=wt.stamp()
wt.penup()
wt.goto(0,1100)
wt.pendown()
wt.color('white')
if i==0 and i==n:
wt.clearstamp(s7)
break
elif i==1 and i==n:
wt.clearstamp(s3)
wt.clearstamp(s4)
wt.clearstamp(s5)
wt.clearstamp(s6)
wt.clearstamp(s7)
break
elif i==2 and i==n:
wt.clearstamp(s1)
wt.clearstamp(s4)
break
elif i==3 and i==n:
wt.clearstamp(s4)
wt.clearstamp(s5)
break
elif i==4 and i==n:
wt.clearstamp(s3)
wt.clearstamp(s5)
wt.clearstamp(s6)
break
elif i==5 and i==n:
wt.clearstamp(s2)
wt.clearstamp(s5)
break
elif i==6 and i==n:
wt.clearstamp(s2)
break
elif i==7 and i==n:
wt.clearstamp(s4)
wt.clearstamp(s5)
wt.clearstamp(s6)
wt.clearstamp(s7)
break
elif i==8 and i==n:
break
elif i==9 and i==n:
wt.clearstamp(s5)
break
def tick():
a=time.strftime('%Y %m %d %H %M %S',time.localtime())
b=a.split(' ')
)
sh1=int(b[3][0])
sh2=int(b[3][1])
ri1=int(b[2][0])
ri2=int(b[2][1])
yu1=int(b[1][0])
yu2=int(b[1][1])
ni1=int(b[0][0])
ni2=int(b[0][1])
ni3=int(b[0][2])
ni4=int(b[0][3])
szz(sh1,'green',h1,-130,-130)
szz(sh2,'green',h2,-10,-130)
szz(ri1,'orange',r1,450,130)
szz(ri2,'orange',r2,570,130)
szz(yu1,'red',y1,160,130)
szz(yu2,'red',y2,280,130)
szz(ni1,'pink',n1,-370,130)
szz(ni2,'pink',n2,-250,130)
szz(ni3,'pink',n3,-130,130)
szz(ni4,'pink',n4,-10,130)
t.ontimer(tick,500)
t.pensize(5)
n1=t.Turtle()
n2=t.Turtle()
n3=t.Turtle()
n4=t.Turtle()
y1=t.Turtle()
y2=t.Turtle()
r1=t.Turtle()
r2=t.Turtle()
h1=t.Turtle()
h2=t.Turtle()
write()
tick()
t.hideturtle()
t.update()
t.mainloop()

 

标签:Turtle,wt,int,szz,数码管,130,绘制,clearstamp
来源: https://www.cnblogs.com/2500435557qq/p/15450612.html