还没有表白神器?情人节来喽,快为心爱的她送上一份专属的礼物吧~

网友投稿 216 2022-09-06


还没有表白神器?情人节来喽,快为心爱的她送上一份专属的礼物吧~

Hello,大家好我叫是Dream呀,一个有趣的Python博主,小白一枚,多多关照 ?入门须知:这片乐园从不缺乏天才,努力才是你的最终入场券!最后,愿我们都能在看不到的地方闪闪发光,一起加油进步“一万次悲伤,依然会有Dream,我一直在最温暖的地方等你”,唱的就是我!哈哈哈~

​​前言:​​一转眼,又是一年情人节,今年你是否还是一个人呢?

if 不是: 祝福你们,看下去,看完感情牢固 print('成功进入好男人关卡')elif 是: 抱抱铁子,看下去,看完脱单 print('成功进入海王关卡')

一、背景故事

情人节其前夕,又有许多小伙伴们纷纷私信Dream,能不能帮忙脱一下单啊,出一期表白神器!更有许多小伙伴因为去年用过这个: python跨年表白神器–你值得拥有!, 今年更是成功加入海王行列,纷纷来感谢Dream,问我是否还有别的好东西。 一个资深老海王的自述(不是):好东西是有的!还有很多!

于是冒着情人节不和女朋友一起过的风险,Dream连夜赶制最新表白神器。应广大朋友们的需求它来喽:情人节专属礼物,快送给最心爱的她吧~话不多说先看效果:

????????????哎嘿嘿,是不是非常的nice呀!看到这先别着急,为了我的情人节着想,是不是得先给我来个一键三连呀!!!

接下来让我们慢慢来聊,请大家前排就坐,爆米花自取哟(点赞+收藏相当于一份爆米花????????????)

二、制作过程

1.交互界面

这里使用定义了clear_screen()函数来实现对每一次动画的清屏,有利于下一次动画的展示。全局运用了turtle库、time时间库、random随机库,以及tkinter库和threading库。

安装方法:cmd之后直接pip install turtle(所需要的库的名称)

# 实现清屏def clear_screen(): turtle.penup() #画笔抬起 turtle.goto(0,0) #定位到(0,0) turtle.color('white') turtle.pensize(800) #画笔粗细 turtle.pendown() #画笔落下 turtle.setheading(0) #设置朝向 turtle.fd(300) #前进 turtle.bk(600) #后退# 初始化海龟的位置def go_start(x, y, state): turtle.pendown() if state else turtle.penup() turtle.goto(x, y)#画线,state为真时海龟回到原点,为假时不回到原来的出发点def draw_line(length, angle, state): turtle.pensize(1) turtle.pendown() turtle.setheading(angle) turtle.fd(length) turtle.bk(length) if state else turtle.penup() turtle.penup()

2.绘制发射爱心的小人

这里是海龟画图的一些操作:

# 画出发射爱心的小人def draw_people(x, y): turtle.speed(0) turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.pensize(2) turtle.color('black') turtle.setheading(0) turtle.circle(35, 360) turtle.penup() turtle.pensize(3) turtle.setheading(90) turtle.fd(45) turtle.setheading(180) turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.pendown() turtle.circle(4, 360) turtle.penup() turtle.goto(x, y) turtle.pensize(2) turtle.setheading(0) turtle.fd(20) turtle.setheading(90) turtle.fd(20) turtle.setheading(-90) turtle.pendown() turtle.circle(5, 180) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.setheading(60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(40) turtle.setheading(0) turtle.fd(35) turtle.setheading(-60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(60) turtle.setheading(-135) turtle.fd(60) turtle.bk(60) turtle.setheading(-45) turtle.fd(30) turtle.setheading(-135) turtle.fd(35) turtle.penup()

3.绘制一箭穿心

这里面的文字都是可以根据自己需要进行修改的,大家按自己的需求来改就可以啦!

# 画爱心def draw_heart(size): turtle.color('red', 'pink') turtle.pensize(2) turtle.pendown() turtle.setheading(150) turtle.begin_fill() turtle.fd(size) turtle.circle(size * -3.745, 45) turtle.circle(size * -1.431, 165) turtle.left(120) turtle.circle(size * -1.431, 165) turtle.circle(size * -3.745, 45) turtle.fd(size) turtle.end_fill() turtle.speed(0)# 画箭羽def draw_feather(size): angle = 30 # 箭的倾角 feather_num = size // 6 # 羽毛的数量 feather_length = size // 3 # 羽毛的长度 feather_gap = size // 10 # 羽毛的间隔 for i in range(feather_num): draw_line(feather_gap, angle + 180, False) # 箭柄,不折返 draw_line(feather_length, angle + 145, True) # 羽翼,要折返 draw_line(feather_length, angle + 145, False) draw_line(feather_num * feather_gap, angle, False) draw_line(feather_length, angle + 145 + 180, False) for i in range(feather_num): draw_line(feather_gap, angle + 180, False) # 箭柄,不折返 draw_line(feather_length, angle - 145, True) # 羽翼,要折返 draw_line(feather_length, angle - 145, False) draw_line(feather_num * feather_gap, angle, False) draw_line(feather_length, angle - 145 + 180, False)# 画一箭穿心,最后箭的头没有画出来,用海龟来代替def arrow_heart(x, y, size): go_start(x, y, False) draw_heart(size * 1.15) turtle.setheading(-150) turtle.penup() turtle.fd(size * 2.2) draw_heart(size) turtle.penup() turtle.setheading(150) turtle.fd(size * 2.2) turtle.color('black') draw_feather(size) turtle.pensize(4) turtle.setheading(30) turtle.pendown() turtle.fd(size * 2) turtle.penup() turtle.setheading(29) turtle.fd(size * 5.7) turtle.color('black') turtle.pensize(4) turtle.pendown() turtle.fd(size * 1.2)#显示倒数3,2,1def draw_0(i): turtle.speed(0) turtle.penup() turtle.hideturtle() # 隐藏箭头显示 turtle.goto(-50, -100) turtle.color('red') write = turtle.write(i, font=('宋体', 200, 'normal')) time.sleep(1)# 显示文字def draw_1(): turtle.penup() turtle.hideturtle() #隐藏箭头显示 turtle.goto(-450, 0) turtle.color('red') write = turtle.write('宝贝,情人节快乐????????????', font=('宋体', 60, 'normal')) time.sleep(2)# 显示发射爱心的小人儿def draw_2(): turtle.speed(3) draw_people(-250, 20) turtle.penup() turtle.goto(-150, -30) draw_heart(14) turtle.penup() turtle.goto(-20, -60) draw_heart(25) turtle.penup() turtle.goto(205, -100) draw_heart(43) turtle.hideturtle() time.sleep(2)def draw_3(): turtle.penup() turtle.hideturtle() # 隐藏箭头显示 turtle.goto(-220, 50) turtle.color('red') write = turtle.write('????宝贝', font=('宋体', 60, 'normal')) turtle.penup() turtle.goto(0, -50) write = turtle.write('宝贝????', font=('宋体', 60, 'normal')) time.sleep(2)# 显示一箭穿心def draw_4(): turtle.speed(1) turtle.penup() turtle.goto(-410, -200) turtle.color('pink') turtle.pendown() turtle.write('猫咪公主 狗王', font=('wisdom', 60, 'normal')) turtle.speed(1) turtle.penup() turtle.color("red") turtle.goto(-31, -220) turtle.write('❤',font=('wisdom', 80, 'normal')) arrow_heart(20, -60, 51) turtle.showturtle()

4.浪漫弹窗绘制

这里使用了tkinter模块来进行小弹窗的绘制,最后是用for循环来实现弹窗的重复性和随机性,这也是我觉得最大的创新之处吧!惊喜重重,满满心意与浪漫,哈哈哈。

def dow(): window = tk.Tk() width = window.winfo_screenwidth() height = window.winfo_screenheight() a = random.randrange(0, width) b = random.randrange(0, height) window.title('宝贝!') window.geometry("200x50" + "+" + str(a) + "+" + str(b)) tk.Label(window, text='????宝贝我爱你????!', # 标签的文字 bg='pink', # 背景颜色 font=('..', 17), # 字体和字体大小 width=18, height=2 # 标签长宽 ).pack() # 固定窗口位置 window.mainloop()number=[3,2,1] #储存显示界面倒数数字1,2,3if __name__ == '__main__': turtle.setup(900, 500) #调画布的尺寸 for i in number: draw_0(i) clear_screen() draw_1() clear_screen() draw_2() clear_screen() draw_3() clear_screen() draw_4() time.sleep(5) # 弹窗设置 threads = [] for i in range(200): # 需要的弹框数量 t = threading.Thread(target=dow) threads.append(t) time.sleep(0.01) threads[i].start()

三、源码分享

源码来喽:

# Time : 2022/2/14 12:21# File : 情人节.py# Author : 是Dream呀!# VX : Xu18300396393# 一万次悲伤,依然会有Dream,我一直在最温暖的地方等你!import turtleimport timeimport randomimport tkinter as tkimport threading# 实现清屏def clear_screen(): turtle.penup() #画笔抬起 turtle.goto(0,0) #定位到(0,0) turtle.color('white') turtle.pensize(800) #画笔粗细 turtle.pendown() #画笔落下 turtle.setheading(0) #设置朝向 turtle.fd(300) #前进 turtle.bk(600) #后退# 初始化海龟的位置def go_start(x, y, state): turtle.pendown() if state else turtle.penup() turtle.goto(x, y)#画线,state为真时海龟回到原点,为假时不回到原来的出发点def draw_line(length, angle, state): turtle.pensize(1) turtle.pendown() turtle.setheading(angle) turtle.fd(length) turtle.bk(length) if state else turtle.penup() turtle.penup()# 画出发射爱心的小人def draw_people(x, y): turtle.speed(0) turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.pensize(2) turtle.color('black') turtle.setheading(0) turtle.circle(35, 360) turtle.penup() turtle.pensize(3) turtle.setheading(90) turtle.fd(45) turtle.setheading(180) turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.pendown() turtle.circle(4, 360) turtle.penup() turtle.goto(x, y) turtle.pensize(2) turtle.setheading(0) turtle.fd(20) turtle.setheading(90) turtle.fd(20) turtle.setheading(-90) turtle.pendown() turtle.circle(5, 180) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(20) turtle.setheading(0) turtle.fd(35) turtle.setheading(60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(40) turtle.setheading(0) turtle.fd(35) turtle.setheading(-60) turtle.fd(10) turtle.penup() turtle.goto(x, y) turtle.setheading(-90) turtle.pendown() turtle.fd(60) turtle.setheading(-135) turtle.fd(60) turtle.bk(60) turtle.setheading(-45) turtle.fd(30) turtle.setheading(-135) turtle.fd(35) turtle.penup()# 画爱心def draw_heart(size): turtle.color('red', 'pink') turtle.pensize(2) turtle.pendown() turtle.setheading(150) turtle.begin_fill() turtle.fd(size) turtle.circle(size * -3.745, 45) turtle.circle(size * -1.431, 165) turtle.left(120) turtle.circle(size * -1.431, 165) turtle.circle(size * -3.745, 45) turtle.fd(size) turtle.end_fill() turtle.speed(0)# 画箭羽def draw_feather(size): angle = 30 # 箭的倾角 feather_num = size // 6 # 羽毛的数量 feather_length = size // 3 # 羽毛的长度 feather_gap = size // 10 # 羽毛的间隔 for i in range(feather_num): draw_line(feather_gap, angle + 180, False) # 箭柄,不折返 draw_line(feather_length, angle + 145, True) # 羽翼,要折返 draw_line(feather_length, angle + 145, False) draw_line(feather_num * feather_gap, angle, False) draw_line(feather_length, angle + 145 + 180, False) for i in range(feather_num): draw_line(feather_gap, angle + 180, False) # 箭柄,不折返 draw_line(feather_length, angle - 145, True) # 羽翼,要折返 draw_line(feather_length, angle - 145, False) draw_line(feather_num * feather_gap, angle, False) draw_line(feather_length, angle - 145 + 180, False)# 画一箭穿心,最后箭的头没有画出来,用海龟来代替def arrow_heart(x, y, size): go_start(x, y, False) draw_heart(size * 1.15) turtle.setheading(-150) turtle.penup() turtle.fd(size * 2.2) draw_heart(size) turtle.penup() turtle.setheading(150) turtle.fd(size * 2.2) turtle.color('black') draw_feather(size) turtle.pensize(4) turtle.setheading(30) turtle.pendown() turtle.fd(size * 2) turtle.penup() turtle.setheading(29) turtle.fd(size * 5.7) turtle.color('black') turtle.pensize(4) turtle.pendown() turtle.fd(size * 1.2)#显示倒数3,2,1def draw_0(i): turtle.speed(0) turtle.penup() turtle.hideturtle() # 隐藏箭头显示 turtle.goto(-50, -100) turtle.color('red') write = turtle.write(i, font=('宋体', 200, 'normal')) time.sleep(1)# 显示文字def draw_1(): turtle.penup() turtle.hideturtle() #隐藏箭头显示 turtle.goto(-450, 0) turtle.color('red') write = turtle.write('宝贝,情人节快乐????????????', font=('宋体', 60, 'normal')) time.sleep(2)# 显示发射爱心的小人儿def draw_2(): turtle.speed(3) draw_people(-250, 20) turtle.penup() turtle.goto(-150, -30) draw_heart(14) turtle.penup() turtle.goto(-20, -60) draw_heart(25) turtle.penup() turtle.goto(205, -100) draw_heart(43) turtle.hideturtle() time.sleep(2)def draw_3(): turtle.penup() turtle.hideturtle() # 隐藏箭头显示 turtle.goto(-220, 50) turtle.color('red') write = turtle.write('????宝贝', font=('宋体', 60, 'normal')) turtle.penup() turtle.goto(0, -50) write = turtle.write('宝贝????', font=('宋体', 60, 'normal')) time.sleep(2)# 显示一箭穿心def draw_4(): turtle.speed(1) turtle.penup() turtle.goto(-410, -200) turtle.color('pink') turtle.pendown() turtle.write('猫咪公主 狗王', font=('wisdom', 60, 'normal')) turtle.speed(1) turtle.penup() turtle.color("red") turtle.goto(-31, -220) turtle.write('❤',font=('wisdom', 80, 'normal')) arrow_heart(20, -60, 51) turtle.showturtle()def dow(): window = tk.Tk() width = window.winfo_screenwidth() height = window.winfo_screenheight() a = random.randrange(0, width) b = random.randrange(0, height) window.title('宝贝!') window.geometry("200x50" + "+" + str(a) + "+" + str(b)) tk.Label(window, text='????宝贝我爱你????!', # 标签的文字 bg='pink', # 背景颜色 font=('..', 17), # 字体和字体大小 width=18, height=2 # 标签长宽 ).pack() # 固定窗口位置 window.mainloop()number=[3,2,1] #储存显示界面倒数数字1,2,3if __name__ == '__main__': turtle.setup(900, 500) #调画布的尺寸 for i in number: draw_0(i) clear_screen() draw_1() clear_screen() draw_2() clear_screen() draw_3() clear_screen() draw_4() time.sleep(5) # 弹窗设置 threads = [] for i in range(200): # 需要的弹框数量 t = threading.Thread(target=dow) threads.append(t) time.sleep(0.01) threads[i].start()

四、美好祝愿

希望大家在情人节都可以和喜欢的人在一起,送上那棵专属于她or他的专属礼物!天天开心,好好生活,我一直都在哟~(有任何问题的话,欢迎评论区或者私信我嗷,我都会看的!)

五、原工程文件分享

如果你实在是不懂Python,那就直接下载这个压缩包就可以把,一键运行即可,需要自取:

情人节表白神器exe文件+直接运行就可以

好啦,这就是今天要分享给大家的全部内容了,我们下期再见!

❤️❤️❤️如果你喜欢的话,就不要吝惜你的一键三连了~


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何爬音乐--一看你就会!(适合爬山的音乐)
下一篇:详解SpringBoot封装使用JDBC
相关文章

 发表评论

暂时没有评论,来抢沙发吧~