300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 叮咚~您的新年礼物到啦 请查收:虎来喽----Python打造虎年祝福神器

叮咚~您的新年礼物到啦 请查收:虎来喽----Python打造虎年祝福神器

时间:2020-03-03 06:32:26

相关推荐

叮咚~您的新年礼物到啦 请查收:虎来喽----Python打造虎年祝福神器

📢📢📢📣📣📣

🌻🌻🌻Hello,大家好我叫是Dream呀,一个有趣的Python博主,多多关照😜😜😜

🏅🏅🏅CSDN Python领域优质创作者,大二在读,欢迎大家找我合作学习(文末有VX 想进学习交流群or学习资料 欢迎+++)

💕入门须知:这片乐园从不缺乏天才,努力才是你的最终入场券!🚀🚀🚀

💓最后,愿我们都能在看不到的地方闪闪发光,一起加油进步🍺🍺🍺

🍉🍉🍉“一万次悲伤,依然会有Dream,我一直在最温暖的地方等你”,唱的就是我!哈哈哈~🌈🌈🌈

🌟🌟🌟✨✨✨

前言:时光飞快,岁月荏苒,转眼间,虎年要来了!Dream在这里祝所有朋友们:虎年快乐,虎虎生威,所遇皆所求!

悄悄告诉大家:凡是三连此文章的小伙伴,来年都可以走桃花运,脱单脱到手软~(评论区是相亲区,欢迎大家留言自己优点和对另一半的期望,快去匹配心动程序猿吧🙈🙈🙈)

🍉🍉🍉凡是在此评论区成功牵手者,前来找我领取纪念礼品哟~哈哈哈,开个玩笑,我们步入正题!

Python打造虎年祝福神器

背景故事👻👻👻制作过程🚀🚀🚀一、Python Turtle模块画小老虎1. 定义库以及初始化界面2. 画出左右两只耳朵3. 画出小老虎头部轮廓4. 画出老虎的两只眼睛5. 画出老虎的鼻子和嘴巴6. 画出小老虎的左右肢体和脚趾7. 在需要的位置写上我们的新年祝福二、弹窗设置三、倒计时页面设计1. 实现清屏功能以及初始化位置2. 显示倒数3,2,13. 显示我们需要的文字4. 设定代码运行入口,调用目标函数结果展示💕💕💕源码分享🌈🌈🌈exe打包文件自取☀️☀️☀️

背景故事👻👻👻

🌻🌻🌻虎年将至,值此新春佳节之际,各大社区更是你争我赶纷纷发起春节征文活动,作为CSDN的一位老朋友,我不允许我所在社区的小伙伴们还没有自己特殊的虎年神器,于是经过一晚上…又一晚上…又又又一晚上…的思考,我还是没有思路😭 😭 😭

正当我一筹莫展之际,几位粉丝朋友们的小请求点醒了我:

对呀,我何不用Python画一个老虎出来呢,加之增添几个功能,打造成一款虎年祝福神器!我瞬间灵感爆发,话不多说,先看成品🏃🏃🏃:

首先是刚打开时的倒数界面,神秘感十足:

倒数结束后,来到我们的展示环节:

最后,是我们的成果,一直可爱的小老虎以及满屏的弹窗祝福:

看到这,是不是好奇心十足呢,先不要着急,看在博主这么辛苦的份上,给小Dream来个一键三连吧~😜😜😜

谢谢大家,大家前排就坐:

制作过程🚀🚀🚀

一、Python Turtle模块画小老虎

在这里,我们使用了Python中的一个非常好玩的库:Turtle,也就是我们常说的海龟画图!不懂的同学可以自行参考学习这篇文章,在这里不做过多的讲解:海龟画图全解–值得你一看!

1. 定义库以及初始化界面

def laohu():import turtle as t# 设置幕布大小及颜色t.screensize(50, 50, bg='yellow')t.title("老虎宝宝")t.shape("classic")t.pensize(10)t.color("orange")t.fillcolor("pink")t.speed(100)t.hideturtle()

2. 画出左右两只耳朵

# 左耳t.penup()t.goto(-105, 97)t.setheading(160)t.begin_fill()t.pendown()t.circle(-30, 230)t.setheading(180)t.circle(37, 90)t.end_fill()# 右耳t.penup()t.goto(105, 97)t.setheading(20)t.begin_fill()t.pendown()t.circle(30, 230)t.setheading(0)t.circle(-37, 90)t.end_fill()

3. 画出小老虎头部轮廓

# 头部轮廓t.penup()t.goto(-67, 140)t.setheading(30)t.pendown()t.circle(-134, 60)t.penup()t.goto(-50, -25)t.setheading(180)t.pendown()t.circle(-100, 30)t.circle(-30, 90)t.setheading(100)t.circle(-200, 20)t.penup()t.goto(50, -25)t.setheading(0)t.pendown()t.circle(100, 30)t.circle(30, 90)t.setheading(80)t.circle(200, 20)

4. 画出老虎的两只眼睛

# 两虎眼# 左眼t.penup()t.goto(-90, 25)t.setheading(-45)t.fillcolor("orange")t.begin_fill()t.pendown()# 椭圆绘制技巧a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.1t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("pink")t.penup()t.goto(-53, 43)t.setheading(0)t.begin_fill()t.pendown()t.circle(19, 360)t.end_fill()t.penup()t.pensize(4)t.goto(-60, 57)t.setheading(30)t.pendown()t.circle(-12, 60)# 右眼t.penup()t.goto(90, 25)t.setheading(45)t.pensize(2)t.fillcolor("orange")t.begin_fill()t.pendown()# 椭圆绘制技巧a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.1t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("pink")t.penup()t.goto(53, 43)t.setheading(0)t.begin_fill()t.pendown()t.circle(13, 360)t.end_fill()t.penup()t.pensize(4)t.goto(60, 57)t.setheading(150)t.pendown()t.circle(12, 60)

5. 画出老虎的鼻子和嘴巴

# 鼻子和嘴吧t.penup()t.goto(-16, 20)t.setheading(-90)t.fillcolor("pink")t.begin_fill()t.pendown()a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3)t.fd(a)else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()t.penup()t.goto(-24, 0)t.setheading(-60)t.pendown()t.circle(28, 120)

6. 画出小老虎的左右肢体和脚趾

# 小老虎肢体# 左肢t.color("orange")t.penup()t.goto(-65, -24)t.setheading(-140)t.begin_fill()t.pendown()t.circle(100, 40)t.setheading(180)t.circle(30, 40)t.setheading(-40)t.circle(40, 40)t.setheading(-150)a = 0.5for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.05t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长elif 30 <= i < 60 or 90 <= i < 100:a = a - 0.05t.lt(3)t.fd(a)t.setheading(93)t.circle(-150, 30)t.end_fill()t.penup()t.goto(-85, -115)t.setheading(-150)t.color("pink", "pink")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()# 每个脚趾绘制函数def toe(x, y):t.begin_fill()t.goto(x, y)t.circle(3, 360)t.end_fill()t.penup()toe(-98, -120)toe(-96, -110)toe(-88, -105)toe(-80, -105)# 右肢t.color("orange")t.penup()t.goto(65, -24)t.setheading(-40)t.begin_fill()t.pendown()t.circle(-100, 40)t.setheading(0)t.circle(-30, 40)t.setheading(-140)t.circle(-40, 40)t.setheading(-30)a = 0.5for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.05t.rt(3) # 向左转3度t.fd(a) # 向前走a的步长elif 30 <= i < 60 or 90 <= i < 100:a = a - 0.05t.rt(3)t.fd(a)t.setheading(87)t.circle(150, 30)t.end_fill()t.penup()t.goto(85, -115)t.setheading(150)t.color("pink", "pink")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()t.penup()toe(98, -120)toe(96, -110)toe(88, -105)toe(80, -105)

7. 在需要的位置写上我们的新年祝福

t.goto(-57, -140)t.color("orange")t.setheading(-20)t.pendown()t.circle(165, 40)t.penup()t.goto(0, 180)t.write("祝大家虎年快乐,虎虎生威!",align="center", font=("Times", 28, "bold"))t.color("black")t.penup()t.goto(0, 80)t.write("王",align="center", font=("Times", 38, "bold"))t.penup()t.goto(0, -5)t.write("一 一",align="center", font=("Times", 18, "bold"))t.goto(0, -15)t.write("一 一",align="center", font=("Times", 18, "bold"))t.goto(0, -25)t.write("一 一",align="center", font=("Times", 18, "bold"))

看到这,我们的小老虎部分就已经大功告成了,大家可以先欣赏一下我们的小老虎:

二、弹窗设置

在必要处修改我们的数据就可以啦,大家以后都可以拿这个去用!

# 弹窗设置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='red', # 背景颜色font=('..', 17), # 字体和字体大小width=18, height=2 # 标签长宽).pack() # 固定窗口位置window.mainloop()

三、倒计时页面设计

1. 实现清屏功能以及初始化位置

import turtleimport timeimport randomimport tkinter as tkimport threading# 实现清屏def clear_screen():turtle.screensize(50, 50, bg='yellow')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. 显示倒数3,2,1

#显示倒数3,2,1def draw_0(i):turtle.screensize(50, 50, bg='yellow')turtle.speed(0)turtle.penup()turtle.hideturtle() # 隐藏箭头显示turtle.goto(-50, -100)turtle.color('red')write = turtle.write(i, font=('宋体', 200, 'normal'))time.sleep(1)

3. 显示我们需要的文字

# 显示文字def draw_1():turtle.penup()turtle.hideturtle() #隐藏箭头显示turtle.goto(-410, 0)turtle.color('red')write = turtle.write('叮咚~新年礼物到啦💕', font=('宋体', 60, 'normal'))time.sleep(2)

4. 设定代码运行入口,调用目标函数

number=[3,2,1] #储存显示界面倒数数字1,2,3if __name__ == '__main__':turtle.setup(900, 500)#调画布的尺寸for i in number:turtle.screensize(50, 50, bg='yellow')draw_0(i)clear_screen()turtle.screensize(50, 50, bg='yellow')draw_1()clear_screen()turtle.screensize(50, 50, bg='yellow')laohu()time.sleep(5)threads = []for i in range(100): # 需要的弹框数量t = threading.Thread(target=dow)threads.append(t)time.sleep(0.01)threads[i].start()

结果展示💕💕💕

最后就是我们的结果啦,快去试试吧!如果有任何不懂的地方,欢迎在最下方添加我的vx,乐意为你排忧解难~

源码分享🌈🌈🌈

import turtleimport timeimport randomimport tkinter as tkimport threading# 实现清屏def clear_screen():turtle.screensize(50, 50, bg='yellow')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()#显示倒数3,2,1def draw_0(i):turtle.screensize(50, 50, bg='yellow')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(-410, 0)turtle.color('red')write = turtle.write('叮咚~新年礼物到啦💕', font=('宋体', 60, 'normal'))time.sleep(2)def laohu():import turtle as t# 设置幕布大小及颜色t.screensize(50, 50, bg='yellow')t.title("老虎宝宝")t.shape("classic")t.pensize(10)t.color("orange")t.fillcolor("pink")t.speed(100)t.hideturtle()# 左耳t.penup()t.goto(-105, 97)t.setheading(160)t.begin_fill()t.pendown()t.circle(-30, 230)t.setheading(180)t.circle(37, 90)t.end_fill()# 右耳t.penup()t.goto(105, 97)t.setheading(20)t.begin_fill()t.pendown()t.circle(30, 230)t.setheading(0)t.circle(-37, 90)t.end_fill()# 头部轮廓t.penup()t.goto(-67, 140)t.setheading(30)t.pendown()t.circle(-134, 60)t.penup()t.goto(-50, -25)t.setheading(180)t.pendown()t.circle(-100, 30)t.circle(-30, 90)t.setheading(100)t.circle(-200, 20)t.penup()t.goto(50, -25)t.setheading(0)t.pendown()t.circle(100, 30)t.circle(30, 90)t.setheading(80)t.circle(200, 20)# 两虎眼# 左眼t.penup()t.goto(-90, 25)t.setheading(-45)t.fillcolor("orange")t.begin_fill()t.pendown()# 椭圆绘制技巧a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.1t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("pink")t.penup()t.goto(-53, 43)t.setheading(0)t.begin_fill()t.pendown()t.circle(19, 360)t.end_fill()t.penup()t.pensize(4)t.goto(-60, 57)t.setheading(30)t.pendown()t.circle(-12, 60)# 右眼t.penup()t.goto(90, 25)t.setheading(45)t.pensize(2)t.fillcolor("orange")t.begin_fill()t.pendown()# 椭圆绘制技巧a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.1t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.1t.lt(3)t.fd(a)t.end_fill()t.fillcolor("pink")t.penup()t.goto(53, 43)t.setheading(0)t.begin_fill()t.pendown()t.circle(13, 360)t.end_fill()t.penup()t.pensize(4)t.goto(60, 57)t.setheading(150)t.pendown()t.circle(12, 60)# 鼻子和嘴吧t.penup()t.goto(-16, 20)t.setheading(-90)t.fillcolor("pink")t.begin_fill()t.pendown()a = 0.2for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3)t.fd(a)else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()t.penup()t.goto(-24, 0)t.setheading(-60)t.pendown()t.circle(28, 120)# 小老虎肢体# 左肢t.color("orange")t.penup()t.goto(-65, -24)t.setheading(-140)t.begin_fill()t.pendown()t.circle(100, 40)t.setheading(180)t.circle(30, 40)t.setheading(-40)t.circle(40, 40)t.setheading(-150)a = 0.5for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.05t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长elif 30 <= i < 60 or 90 <= i < 100:a = a - 0.05t.lt(3)t.fd(a)t.setheading(93)t.circle(-150, 30)t.end_fill()t.penup()t.goto(-85, -115)t.setheading(-150)t.color("pink", "pink")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()# 每个脚趾绘制函数def toe(x, y):t.begin_fill()t.goto(x, y)t.circle(3, 360)t.end_fill()t.penup()toe(-98, -120)toe(-96, -110)toe(-88, -105)toe(-80, -105)# 右肢t.color("orange")t.penup()t.goto(65, -24)t.setheading(-40)t.begin_fill()t.pendown()t.circle(-100, 40)t.setheading(0)t.circle(-30, 40)t.setheading(-140)t.circle(-40, 40)t.setheading(-30)a = 0.5for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.05t.rt(3) # 向左转3度t.fd(a) # 向前走a的步长elif 30 <= i < 60 or 90 <= i < 100:a = a - 0.05t.rt(3)t.fd(a)t.setheading(87)t.circle(150, 30)t.end_fill()t.penup()t.goto(85, -115)t.setheading(150)t.color("pink", "pink")t.begin_fill()t.pendown()a = 0.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a = a + 0.03t.lt(3) # 向左转3度t.fd(a) # 向前走a的步长else:a = a - 0.03t.lt(3)t.fd(a)t.end_fill()t.penup()toe(98, -120)toe(96, -110)toe(88, -105)toe(80, -105)t.goto(-57, -140)t.color("orange")t.setheading(-20)t.pendown()t.circle(165, 40)t.penup()t.goto(0, 180)t.write("祝大家虎年快乐,虎虎生威!",align="center", font=("Times", 28, "bold"))t.color("black")t.penup()t.goto(0, 80)t.write("王",align="center", font=("Times", 38, "bold"))t.penup()t.goto(0, -5)t.write("一 一",align="center", font=("Times", 18, "bold"))t.goto(0, -15)t.write("一 一",align="center", font=("Times", 18, "bold"))t.goto(0, -25)t.write("一 一",align="center", font=("Times", 18, "bold"))# 弹窗设置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='red', # 背景颜色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:turtle.screensize(50, 50, bg='yellow')draw_0(i)clear_screen()turtle.screensize(50, 50, bg='yellow')draw_1()clear_screen()turtle.screensize(50, 50, bg='yellow')laohu()time.sleep(5)threads = []for i in range(100): # 需要的弹框数量t = threading.Thread(target=dow)threads.append(t)time.sleep(0.01)threads[i].start()

exe打包文件自取☀️☀️☀️

考虑到大家可能对Python不太了解,我在这里为大家打包好了可以直接运行的exe文件,大家直接发送给需要的人就可以啦,大家自取,别忘了五星好评哟~

虎年画虎祝福已经打包的exe文件,直接可以用,需要自取.zip

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。