python学习 第七个程序 七段数码管显示日期

# SevenDigitsDraw.py
import turtle
import time


def drawLine():
turtle.penup()
turtle.fd(5)
turtle.pendown()
turtle.fd(40)
turtle.penup()
turtle.fd(5)
turtle.pendown()

def goLine():
turtle.penup()
turtle.fd(50)
turtle.right(90)
turtle.pendown()


def goToInialPos(x, y):
turtle.penup()
turtle.goto(x, y - 50)
turtle.seth(0)
turtle.pensize(5)
turtle.speed(0)
turtle.pendown()


def drawDigit(digit, x, y):

goToInialPos(x, y-50)
if digit in ['2', '3', '4', '5', '6', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()

if digit in ['0', '1', '3', '4', '5', '6', '7', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()
if digit in ['0', '2', '3', '5', '6', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()
if digit in ['0', '2', '6', '8']:
drawLine()
turtle.right(90)
else:
goLine()
turtle.left(90)
if digit in ['0', '4', '5', '6', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()
if digit in ['0', '2', '3', '5', '6', '7', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()
if digit in ['0', '1', '2', '3', '4', '7', '8', '9']:
drawLine()
turtle.right(90)
else:
goLine()


def drawTime(digits, x, y):
turtle.pencolor("red")
for i in digits:
if i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
drawDigit(i, x, y)
x = x + 50 + 10
elif i == '+':
turtle.penup()
turtle.seth(0)
turtle.fd(10)
turtle.pendown()
turtle.write("年", font = ("Arial", 20, "normal"))
turtle.pencolor("green")
x = x + 30
elif i == '-':
turtle.penup()
turtle.seth(0)
turtle.fd(10)
turtle.pendown()
turtle.write("月", font = ("Arial", 20, "normal"))
turtle.pencolor("blue")
x = x + 30
elif i == '=':
turtle.penup()
turtle.seth(0)
turtle.fd(10)
turtle.pendown()
turtle.write("日", font = ("Arial", 20, "normal"))
x = x + 30
turtle.done()


def main():
t = time.gmtime()
timeStr = time.strftime("%Y+%m-%d=", t)
drawTime(timeStr, -200, 50)


main()




猜你喜欢

转载自www.cnblogs.com/wumingoo1/p/10321621.html
今日推荐