爱心(Python)

代码如下:

import turtle
import time

def LittleHeart():
    for i in range(200):
        turtle.right(1)
        turtle.forward(2)
love = input('请输入表白语句,默认为输入为"I Love you": ')
me = input('请输入您心上人的姓名或者昵称:')
if love == '':
    love = 'I Love you'
turtle.setup(width=800, height=500)
turtle.color('red', 'pink')
turtle.pensize(5)
turtle.speed(1)
turtle.up()
turtle.hideturtle()
turtle.goto(0, -180)
turtle.showturtle()
turtle.down()
turtle.speed(2)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
LittleHeart()
turtle.left(120)
LittleHeart()
turtle.forward(224)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.hideturtle()
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('#CD5C5C', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
time.sleep(2)
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('red', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
if me != '':
    turtle.color('black', 'pink')
    time.sleep(2)
    turtle.goto(180, -180)
    turtle.showturtle()
    turtle.write(me, font=(20,), align="center", move=True)
window = turtle.Screen()
window.exitonclick()

爱心(Python)_第1张图片

(语句可以自定义)(输入名字)

你可能感兴趣的:(python)