Python 弹窗设计小人发射爱心
作者:Griffy650 时间:2021-07-16 14:41:01
这些代码里含有弹窗设计,可以根据好友选择来进入不同画面,简单有趣的中秋礼物哦
这是我第一次用turtle画画,水平有限,如有问题,请指正哦!(还没有进一步简化,代码写得很啰嗦。)
如果想发给朋友的话,可以将代码打包为exe,具体步骤如下:
1.先在桌面创建文件夹
2.将要打包的python文件放进该文件夹
3.在该文件夹打开命令行(如图)并输入:pyinstaller -F filename.py(你的文件名)
4.在dist文件夹里就可以找到你想要的小程序啦hhhhhh
先来两张成果图(这是经过弹窗选择后的不同结果)
下面是代码,需要自取哦!
##Author:Griffy
##Date:2021-9-21
from turtle import *
import time
import PySimpleGUI as sg #弹框制作模块
def draw_count_down(i): #倒数
bgcolor('black')
speed(0)
up()
goto(-50,-100)
color('white')
write(i, align="center",font=('Times New Roman', 200, 'bold'))
time.sleep(1)
def draw_moon(): #画月亮
bgcolor('#093FB7')
color('#F4EE00', '#F4EE00')
begin_fill()
speed(2)
up()
goto(0, -300)
down()
circle(300)
end_fill()
def draw_people(): #画小人
up()
fillcolor()
begin_fill()
color('black','white')
goto(-300, 50) # 脖子坐标
down()
circle(75) # 半径为75的脑袋
end_fill()
right(90)
forward(175) # 身体的长度175像素
right(45)
forward(100) # 腿长100像素
up()
goto(-300, -120) # 画另一条腿
down()
left(90)
forward(100)
up()
goto(-300, -5) # 手臂坐标
down()
left(45)
forward(100) # 第一只手臂长度
left(45)
forward(67) # 手掌长度
up()
goto(-300, -40) # 第二只手臂坐标
down()
right(45)
forward(100) # 第二只手臂长度
right(45)
forward(67)
up()
goto(-330, 155) # 第一只眼睛起始坐标
down()
right(45)
forward(50) # 眼睛长度为50
up()
goto(-270, 155) # 第二只眼睛起始坐标
down()
forward(50)
up()
pencolor('#F39F79')
goto(-340,100) #红脸蛋第一只眼
seth(0)
down()
backward(40)
up()
goto(-260, 100) # 红脸蛋第二只眼
down()
forward(40)
time.sleep(1)
def draw_heart(size): # 画爱心
color('red', 'pink')
down()
setheading(150)
begin_fill()
forward(size)
circle(size * -3.745, 45)
circle(size * -1.431, 165)
left(120)
circle(size * -1.431, 165)
circle(size * -3.745, 45)
forward(size)
end_fill()
def send_heart(): #发射爱心
up()
goto(-50, -22)
draw_heart(14)
up()
goto(120, -22)
draw_heart(25)
penup()
goto(305, -22)
draw_heart(43)
def wr_character():
up()
goto(-50,-200)
pencolor('black')
write('中', font=('幼圆', 60, 'bold'))
up()
goto(50,-200)
write('秋', font=('幼圆', 60, 'bold'))
up()
goto(150,-200)
write('快', font=('幼圆', 60, 'bold'))
up()
goto(250,-200)
write('乐', font=('幼圆', 60, 'bold'))
def draw_pupu(): #画便便
up()
shapesize(10, 2)
speed(2)
fillcolor()
color('#805140','#805140')
begin_fill()
goto(-50, -20)
down()
circle(20)
end_fill()
begin_fill()
up()
goto(-50, -80)
down()
circle(40)
end_fill()
begin_fill()
up()
goto(10, -110)
seth(90)
down()
circle(60,180)
seth(0)
forward(120)
end_fill()
def present_good(): #认为我是好人送的礼物
setup(1000,700)
pensize(10)
hideturtle()
numbers=[5,4,3,2,1] #进行倒数
for i in numbers:
draw_count_down(i)
undo()
draw_moon()
draw_people()
send_heart()
wr_character()
done()
def present_bad(): #认为我不好送的礼物
setup(1000, 700)
pensize(10)
hideturtle()
numbers=[5,4,3,2,1] #进行倒数
for i in numbers:
draw_count_down(i)
undo()
draw_moon()
draw_people()
draw_pupu()
wr_character()
done()
layout=[ #弹框内容设计
[sg.Text('请输入你的名字:')],[sg.Input()],
[sg.Text('请回答下面这个问题哦!')],
[sg.Text('xxx是个大好人是吗?')],
[sg.Button('是的是的')],[sg.Button('不是')]
]
sg.popup('你好呀!我是你的好朋友xxx为你定制的中秋节礼物⭐','请按OK键继续') #这是一个简易弹框
time.sleep(1)
window=sg.Window('中秋礼物',layout)
event,value=window.read()
window.close()
if event == '是的是的':
sg.popup(f'{value[0]}请按OK键接收xxx的中秋礼物!♥') #这是一个简易弹框 #这里的value[0],是因为value返回内容为字典
time.sleep(1)
present_good()
else:
sg.popup(f'{value[0]}竟然对xxx有意见,你还想要礼物!!','但是xxx是个大度的人,送你礼物吧','请按OK键接收xxx的中秋礼物!')
present_bad()
弹框里的问题和文字大家可以根据自己的想法进行设计哈!
最后,祝大家中秋快乐!!!
来源:https://blog.csdn.net/weixin_56198196/article/details/120402597
标签:Python,小人,发射爱心
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中使用PIL制作并验证图片验证码
2023-06-05 11:28:33
Python中itertools模块的使用教程详解
2023-08-24 03:07:25
用python爬取分析淘宝商品信息详解技术篇
2022-09-12 23:40:54
![](https://img.aspxhome.com/file/2023/3/90933_0s.jpg)
python获取酷狗音乐top500的下载地址 MP3格式
2021-05-06 04:38:05
![](https://img.aspxhome.com/file/2023/9/78819_0s.jpg)
在SQL Server计算机上运行病毒扫描软件
2009-01-19 14:38:00
总结Python连接CS2000的详细步骤
2023-04-21 20:26:33
![](https://img.aspxhome.com/file/2023/7/70197_0s.png)
django多文件上传,form提交,多对多外键保存的实例
2023-04-13 04:24:12
pytest中文文档之编写断言
2023-05-05 04:11:34
Django应用程序中如何发送电子邮件详解
2023-11-04 02:07:54
![](https://img.aspxhome.com/file/2023/2/65452_0s.png)
Python远程桌面协议RDPY安装使用介绍
2023-11-06 05:37:23
Python根据成绩分析系统浅析
2023-08-02 20:25:07
![](https://img.aspxhome.com/file/2023/4/62024_0s.png)
pandas行和列的获取的实现
2022-06-05 07:57:49
python实现学生信息管理系统
2021-11-27 11:46:42
django 修改server端口号的方法
2022-05-08 15:49:10
![](https://img.aspxhome.com/file/2023/6/72976_0s.png)
Dreamweaver MX 2004表格设计
2008-02-03 11:36:00
![](https://img.aspxhome.com/file/UploadPic/20072/20072311363330s.jpg)
OpenCV图像变换之傅里叶变换的一些应用
2023-12-01 22:11:34
![](https://img.aspxhome.com/file/2023/9/85359_0s.jpg)
PHP实现的简单排列组合算法应用示例
2023-11-18 16:28:40
理解SQL SERVER中的逻辑读,预读和物理读
2012-01-05 19:32:29
服务端XMLHTTP(ServerXMLHTTP in ASP)基本应用(上)
2008-11-11 12:49:00
![](https://img.aspxhome.com/file/UploadPic/200811/11/63u9_google-92s.png)
Python排序算法之插入排序及其优化方案详解
2021-04-03 05:39:31
![](https://img.aspxhome.com/file/2023/6/72086_0s.png)