当前位置:   article > 正文

Python中使用turtle库画与女朋友纪念日_python 展示和女朋友的纪念日倒计时

python 展示和女朋友的纪念日倒计时
import turtle, time
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)
def drawDate(date):
    turtle.pencolor("red")
    for i in date:
        if i == '-':
            turtle.write('年',font=("Arial", 18, "normal"))
            turtle.pencolor("green")
            turtle.fd(40)
        elif i == '=':
            turtle.write('月',font=("Arial", 18, "normal"))
            turtle.pencolor("blue")
            turtle.fd(40)
        elif i == '+':
            turtle.write('日',font=("Arial", 18, "normal"))
            turtle.fd(40)
        else:
            drawDigit(eval(i))
def all(day):
    turtle.goto(-350,-300)
    turtle.pencolor("orange")
    turtle.write('总共',font=("Arial", 40, "normal"))
    turtle.fd(110)
    for j in day:
        drawDigit(eval(j))
    turtle.write('天',font=("Arial", 18, "normal"))
def count(t1,t2,t3):
    t=t1*365
    if t2 in [1,2]:
        t+=t2*30
    if t2 in [3]:
        t=t+91
    if t2==4:
        t+=122
    if t2==5:
        t+=152
    if t2==6:
        t+=183
    if t2==7:
        t+=213
    if t2==8:
        t+=244
    if t2==9:
        t+=275
    if t2==10:
        t+=303
    if t2==11:
        t+=334
    t+=t3
    return(str(t))
def text():
    turtle.penup()
    turtle.goto(-350,370)
    turtle.pendown()
    turtle.write('今天是:',font=("Arial", 18, "normal"))
    turtle.pensize(5)
    turtle.penup()
    turtle.goto(-350,300)
    turtle.pendown()
    drawDate(time.strftime('%Y-%m=%d+',time.gmtime()))
    turtle.penup()
    turtle.goto(-350,200)
    turtle.pensize(1)
    turtle.pendown()
    turtle.pencolor("black")
    turtle.write('XX和XX在一起:',font=("Arial", 18, "normal"))
    turtle.penup()
    turtle.goto(-350,100)
    turtle.pendown()
    turtle.pensize(5)
    drawDate('2018-02=23+')
    turtle.penup()
    turtle.goto(-350,0)
    turtle.pensize(1)
    turtle.pendown()
    turtle.pencolor("black")
    turtle.write('我们一起经历了:',font=("Arial", 18, "normal"))
    turtle.penup()
    turtle.goto(0,-100)
    turtle.pensize(1)
    turtle.pendown()
def main():
    turtle.setup(900, 900, 200, 0)
    text()
    turtle.penup()
    turtle.fd(-350)
    turtle.pensize(5)
#    drawDate('2018-10=10+')
    t1=time.gmtime()
    t2=t1.tm_year-2018
    t3=t1.tm_mon-2
    if t3<0:
        t2-=1
        t3+=12
    t4=t1.tm_mday-23
    if t4<0:
        t3-=1
        if t1.tm_mon-1 in [1,3,5,7,8,10,12]:
            t4+=31
        else:
            t4+=30
    tatol=count(t2,t3,t4)
    drawDate(str(t2)+'-'+str(t3)+'='+str(t4)+'+')
    all(tatol)
    turtle.hideturtle()
    turtle.done()
main()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/179810?site
推荐阅读
相关标签
  

闽ICP备14008679号