|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import turtle
import 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(digit):
if digit in [2, 3, 4, 5, 6, 8, 9]:
drawLine(True)
else:
drawLine(False)
if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9]:
drawLine(True)
else:
drawLine(False)
if digit in [0, 2, 3, 5, 6, 8, 9]:
drawLine(True)
else:
drawLine(False)
if digit in [0, 2, 6, 8]:
drawLine(True)
else:
drawLine(False)
turtle.left(90)
if digit in [0, 4, 5, 6, 8, 9]:
drawLine(True)
else:
drawLine(False)
if digit in [0, 2, 3, 5, 6, 7, 8, 9]:
drawLine(True)
else:
drawLine(False)
if digit in [0, 1, 2, 3, 4, 7, 8, 9]:
drawLine(True)
else:
drawLine(False)
turtle.left(180)
turtle.penup()
turtle.fd(20)
def drawAMPM():
current_time = datetime.datetime.now()
am_pm = "AM" if current_time.hour < 12 else "PM"
if am_pm == "AM":
drawDigit(ord('A'))
else:
drawDigit(ord('P'))
def drawTime():
current_time = datetime.datetime.now().strftime("%I:%M:%S")
for digit in current_time:
if digit == ":":
turtle.write(":", align="center", font=("Arial", 36, "normal"))
turtle.fd(40)
else:
drawDigit(int(digit))
drawAMPM()
def main():
turtle.setup(800, 350, 200, 200)
turtle.penup()
turtle.goto(-200, 0)
turtle.pensize(5)
drawTime()
turtle.hideturtle()
turtle.done()
if __name__ == "__main__":
main()
我想用seven-segment tube显示后面的上午和下午。 上午要A,下午要P。 运行上述代码只显示当前时间。 该怎么修改呢? |
|