到表白的日子了,怕表白不好开口,怕表白没有新意。那你可以看看这篇文章,给她画一个小爱心吧。
import turtle as t
import time
p = t.Turtle()
def Dt():
t = "For you"
for i in t:
p.write(i, align="right", font=("楷体", 20, "bold"))
p.fd(15)
time.sleep(0.3)
def Pt():
p.hideturtle()
p.penup()
p.goto(-180, 0)
Dt()
t.setup(700, 600, 700, 200)
t.title("爱心")
t.fillcolor('red')
t.hideturtle()
t.begin_fill()
t.left(40)
t.fd(150)
t.circle(80, 190)
t.setheading(130)
t.circle(80, 190)
t.fd(150)
t.end_fill()
Pt()
t.done()
首先我们用到了python的turtle库,然后用一系列的画笔控制函数把爱心画了出来,最后填充了红颜色。
大家如果要改变画好呈现的字,可以把 t="替换的文本",改一下。这样就可以自定义文字了。
发给女朋友看的时候,可以用python的pyinstaller库打包成exe文件发给她了。
在终端中输入:pyinstaller -F 文件名.py --noconsole
这个--noconsole是exe文件运行时不显示终端黑框的参数,建议把代码调试好后再打包哦。
执行上一步的时候一定要在你的代码所在的文件夹打开终端执行,不然执行的时候会找不到.py文件的。
执行完后生成的exe文件在dist目录下,直接微信发给她双击就可以显示效果了。