脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python 弹窗设计小人发射爱心

Python 弹窗设计小人发射爱心

2022-01-10 00:14Griffy650 Python

今天小编就为大家分享一篇使用Python画出小人发射爱心的代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

这些代码里含有弹窗设计,可以根据好友选择来进入不同画面,简单有趣的中秋礼物哦

这是我第一次用turtle画画,水平有限,如有问题,请指正哦!(还没有进一步简化,代码写得很啰嗦。)

如果想发给朋友的话,可以将代码打包为exe,具体步骤如下:

  • 1.先在桌面创建文件夹
  • 2.将要打包的python文件放进该文件夹
  • 3.在该文件夹打开命令行(如图)并输入:pyinstaller -f filename.py(你的文件名)
  • 4.在dist文件夹里就可以找到你想要的小程序啦hhhhhh

Python 弹窗设计小人发射爱心

先来两张成果图(这是经过弹窗选择后的不同结果)

Python 弹窗设计小人发射爱心

Python 弹窗设计小人发射爱心

下面是代码,需要自取哦!

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
##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()

弹框里的问题和文字大家可以根据自己的想法进行设计哈!

最后,祝大家中秋快乐!!!

到此这篇关于python 弹窗设计小人发射爱心的文章就介绍到这了,更多相关python 小人发射爱心内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_56198196/article/details/120402597

延伸 · 阅读

精彩推荐