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

yipeiwu_com6年前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模块搜索概念介绍及模块安装方法介绍

Python模块搜索概念介绍及模块安装方法介绍

【import模块】 和C中的#include不同,Python中的import语句并不是简单的把一个文件插入另外一个文件。 导入其实是运行时的运算,程序第一次导入指定文件时,会执行以下...

Python目录和文件处理总结详解

1、判断目录是否存在、判断文件是否存在、创建目录、重命名目录或文件 import os #获取当前目录路径: E:\Work\Projects\python print(os.ge...

Python生成一个迭代器的实操方法

Python生成一个迭代器的实操方法

Python怎么生成一个迭代器,对于需要处理大型数据来说,迭代器是必不可少的,这样可节省大量内存空间,更加合理操作数据。 首先我们打开编辑器,这里以Sublime text3作为示范,...

Python3利用print输出带颜色的彩色字体示例代码

Python3利用print输出带颜色的彩色字体示例代码

前言 这篇文章通过实例给大家讲解Python3中print带颜色输出的格式,下面话不多说了,来一起看看详细的介绍吧 \033[显示方式;前景色;背景色m需要显示的文字\033[0m 其...

Python 实现毫秒级淘宝抢购脚本的示例代码

本篇文章主要介绍了Python 通过selenium实现毫秒级自动抢购的示例代码,通过扫码登录即可自动完成一系列操作,抢购时间精确至毫秒,可抢加购物车等待时间结算的,也可以抢聚划算的商品...