python爱心表白 每天都是浪漫七夕!

yipeiwu_com5年前Python基础

本文为大家分享了python爱心表白的具体代码,供大家参考,具体内容如下

import turtle
import time


# 画爱心的顶部
def LittleHeart():
  for i in range(200):
    turtle.right(1)
    turtle.forward(2)


# 输入表白的语句,默认I Love you
love = 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,0
turtle.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()

运行结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

在Python中pandas.DataFrame重置索引名称的实例

例子: 创建DataFrame ### 导入模块 import numpy as np import pandas as pd import matplotlib.pyplot as...

Python配置文件处理的方法教程

Python配置文件处理的方法教程

前言 在平时的工程中,我们在构建工程时,常常需要用到配置文件,用来配置项目的一些信息,比如数据库,请求网址,文件夹,线程、进程数等信息,这样就可以方便我们通过修改配置文件中的参数来很好地...

详解Python中where()函数的用法

where()的用法 首先强调一下,where()函数对于不同的输入,返回的只是不同的。 1当数组是一维数组时,返回的值是一维的索引,所以只有一组索引数组 2当数组是二维数组时,满足条件...

Python中正则表达式的详细教程

Python中正则表达式的详细教程

1.了解正则表达式     正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符、及这些特定字符的组合,组成一个“规则字符串”,这个“规则...

python学习教程之使用py2exe打包

前言 本文主要给大家介绍了关于python使用py2exe打包的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 遇坑 之前经过折腾,pyinstaller打...