importturtle, datetime
def drawgap(): #
繪製數碼管間隔
turtle.penup()
turtle.fd(5)
def drawline(draw): #
繪製單段數碼管
drawgap()
turtle.pendown()
if draw else
turtle.penup()
turtle.fd(40)
drawgap()
turtle.right(90)
def drawdigit(d): #
根據數字繪製七段數碼管
drawline(true) if d in [2, 3, 4, 5, 6, 8, 9] else drawline(false)#
日中間那一橫
drawline(true) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawline(false)#
日右下角那一豎
drawline(true) if d in [0, 2, 3, 5, 6, 8, 9] else drawline(false)#
日下面那一橫
drawline(true) if d in [0, 2, 6, 8] else drawline(false)#
日左下角那一豎
turtle.left(90)
drawline(true)
if d in [0, 4, 5, 6, 8, 9] else drawline(false)#
日左上角那一豎
drawline(true) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawline(false)#
日上面那一橫
drawline(true) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawline(false)#
日右上角那一豎
turtle.left(180)
turtle.penup()
turtle.fd(20)
defdrawdate(date):
turtle.pencolor(
"red")
for i in
date:
if i == '-'
: turtle.write('年
', font=("
arial
", 36, "
normal"))
turtle.pencolor(
"green")
turtle.fd(50)
elif i == '='
: turtle.write('月
', font=("
arial
", 36, "
normal"))
turtle.pencolor(
"blue")
turtle.fd(50)
elif i == '+'
: turtle.write('日
', font=("
arial
", 36, "
normal"))
turtle.pencolor(
"yellow")
turtle.fd(50)
elif i == '*'
: turtle.write('時
', font=("
arial
", 36, "
normal"))
turtle.pencolor(
"purple")
turtle.fd(50)
elif i == '/'
: turtle.write('分
', font=("
arial
", 36, "
normal"))
turtle.pencolor(
"gold")
turtle.fd(50)
elif i == '$'
: turtle.write('秒
', font=("
arial
", 36, "
normal"))
else
: drawdigit(eval(i))
defmain():
turtle.setup(1400, 350, 200, 200)#
設定視窗大小
7段數碼管繪製
import turtle,time def drawgap turtle.speed 0 設定畫筆速度 fastest 0 fast 10 normal 6 slow 3 slowest 1 turtle.turtle screen.delay 0 畫筆速度無延遲turtle.penup turt...
7段數碼管繪製
import turtle,datetime def drawgap 繪製數碼管間隔 turtle.penup turtle.fd 5 def drawline draw 繪製單段數碼管 drawgap turtle.pendown if draw else turtle.penup turtle....
7段數碼管繪製
import turtle,time defdrawgap turtle.speed 0 設定畫筆速度 fastest 0 fast 10 normal 6 slow 3 slowest 1 turtle.turtle screen.delay 0 畫筆速度無延遲 turtle.penup turt...