import turtleimport time# 画爱心的顶部def LittleHeart(): for i in range(200): turtle.right(1) turtle.forward(2)# 输入表白的语句,默认I Love youlove = input('Please enter a sentence of love, otherwise the default is "I Love you": ')# 输入署名或者赠谁,没有不执行me = input('Please enter pen name, otherwise the default do not execute: ')if love == '': love = 'I Love you'# 窗口大小turtle.setup(width=900, height=500)# 颜色turtle.color('red', 'pink')# 笔粗细turtle.pensize(3)# 速度turtle.speed(1)# 提笔turtle.up()# 隐藏笔turtle.hideturtle()# 去到的坐标,窗口中心为0,0turtle.goto(0, -180)turtle.showturtle()# 画上线turtle.down()turtle.speed(1)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')# 在心中写字 font可以设置字体自己电脑有的都可以设 align开始写字的位置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()