這些代碼里含有彈窗設計,可以根據好友選擇來進入不同畫面,簡單有趣的中秋禮物哦
這是我第一次用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://www.uj5u.com/houduan/301971.html
標籤:python
上一篇:中秋福利鴨
