自己今天第一次做一个python生日贺卡:

效果图

参考之前有位大佬的作品,自己稍微的改造了一下下

 首先:上程序

Birthday.py

  1. """
  2. ---------------------------------------
  3. Author:Zjh
  4. Date: -- :
  5. ---------------------------------------
  6. """
  7. #coding=utf-
  8. import turtle
  9. import random
  10. import time
  11. from turtle import *
  12. from random import *
  13.  
  14. # set the background color for the page
  15. import time
  16. import pygame
  17.  
  18. def make_cake(turtle,x=, y=):
  19. tina = turtle
  20. tina.penup()
  21. tina.color('white')
  22. tina.goto(x, y)
  23. tina.pendown()
  24. tina.begin_fill()
  25. tina.goto(x + , y)
  26. tina.goto(x + , y + )
  27. tina.goto(x - , y + )
  28. tina.goto(x - , y)
  29. tina.goto(x, y)
  30. tina.end_fill()
  31. tina.goto(x, y + )
  32. tina.color('blue')
  33. tina.goto(x, y + )
  34. tina.goto(x, y + )
  35. tina.color('black')
  36. tina.goto(x, y + )
  37. tina.penup()
  38. tina.goto(x, y + )
  39.  
  40. file='media/front.mp3'
  41. pygame.mixer.init() #把mp3初始化出来
  42. #print("播放音乐1")
  43.  
  44. track = pygame.mixer.music.load(file)
  45.  
  46. pygame.mixer.music.play()
  47. #time.sleep()
  48.  
  49. #tommy.reset()
  50.  
  51. bg = turtle.Screen()
  52. bg.bgcolor("black")
  53.  
  54. tommy = turtle.Turtle()
  55. tommy.shape("turtle")
  56. tommy.speed()
  57.  
  58. tommy.penup()
  59. tommy.goto(-,)
  60. tommy.color("orange")
  61. tommy.write(",,ԾㅂԾ,,请小寿星插上耳机后观看哦 ",font=('微软雅黑', , 'normal'))
  62.  
  63. time.sleep()
  64. tommy.clear()
  65.  
  66. x = -
  67. y =
  68. tommy.goto(x,y)
  69. tommy.color("pink")
  70.  
  71. pygame.mixer.music.stop()
  72. file='media/Happy.mp3'
  73. # pygame.mixer.init() #把mp3初始化出来
  74. #print("播放音乐1")
  75. track = pygame.mixer.music.load(file)
  76. pygame.mixer.music.play()
  77.  
  78. time.sleep()
  79.  
  80. tommy.penup()
  81. tommy.goto(x,y------------) #每次减25
  82. tommy.write(" φ(゜▽゜*)♪ 有“声音啦”,接下来我再增加点“五彩斑斓的颜色哦”。。。 ",font=('微软雅黑', , 'normal'))
  83. time.sleep()
  84.  
  85. tommy.clear()
  86.  
  87. tommy.pensize()
  88. # draw lines
  89. tommy.penup()
  90. tommy.goto(-, -)
  91. tommy.color("yellow")
  92. tommy.pensize()
  93. tommy.pendown()
  94. tommy.goto(,-)
  95. tommy.penup()
  96.  
  97. tommy.penup()
  98. tommy.goto(-, -)
  99. tommy.color("purple")
  100. tommy.pensize()
  101. tommy.pendown()
  102. tommy.goto(,-)
  103. tommy.penup()
  104.  
  105. tommy.penup()
  106. tommy.goto(-, -)
  107. tommy.color("teal")
  108. tommy.pensize()
  109. tommy.pendown()
  110. tommy.goto(,-)
  111. tommy.penup()
  112.  
  113. # draw cake
  114. tommy.goto(-,-) #这个是画蛋糕
  115. tommy.begin_fill()
  116. tommy.pendown()
  117. tommy.color("white")
  118. tommy.goto(,-)
  119. tommy.left()
  120. tommy.forward()
  121. tommy.left()
  122. tommy.forward()
  123. tommy.left()
  124. tommy.forward()
  125. tommy.end_fill()
  126. tommy.penup()
  127.  
  128. tommy.goto(-,-) #这个是画蛋糕,到这个坐标去,这个是黄色那层
  129. tommy.begin_fill()
  130. tommy.pendown() #放下画笔
  131. tommy.color("yellow")
  132. tommy.goto(,-)
  133. tommy.left()
  134. #tommy.forward() #向前60码,这个是那个横线
  135. tommy.left()
  136. tommy.forward() #这个是一层的厚度
  137. tommy.left() #这个是根据角度来转方像
  138. tommy.forward()
  139. tommy.left() #这个是根据角度来转方像
  140. tommy.forward()
  141. tommy.end_fill()
  142. tommy.penup()
  143.  
  144. tommy.goto(-,-) #这个是画蛋糕,到这个坐标去,这个是黄色那层
  145. tommy.begin_fill()
  146. tommy.pendown() #放下画笔
  147. tommy.color("#40E0D0")
  148. tommy.goto(,-)
  149. tommy.left()
  150. #tommy.forward() #向前60码,这个是那个横线
  151. tommy.left()
  152. tommy.forward() #这个是一层的厚度
  153. tommy.left() #这个是根据角度来转方像
  154. tommy.forward()
  155. tommy.left() #这个是根据角度来转方像
  156. tommy.forward()
  157. tommy.end_fill()
  158. tommy.penup()
  159.  
  160. tommy.goto(-,-) #这个是画蛋糕,到这个坐标去,最下面那层
  161. tommy.begin_fill()
  162. tommy.pendown() #放下画笔
  163. tommy.color("#BA55D3")
  164. tommy.goto(,-)
  165. tommy.left()
  166. #tommy.forward() #向前60码,这个是那个横线
  167. tommy.left()
  168. tommy.forward() #这个是一层的厚度
  169. tommy.left() #这个是根据角度来转方像
  170. tommy.forward()
  171. tommy.left() #这个是根据角度来转方像
  172. tommy.forward()
  173. tommy.end_fill()
  174. tommy.penup()
  175.  
  176. #draw candles
  177. tommy.goto(-, -)
  178. tommy.color("aquamarine")
  179. tommy.pendown()
  180. tommy.pensize()
  181. tommy.goto(-, -)
  182. tommy.penup()
  183.  
  184. tommy.goto(-, -)
  185. tommy.color("yellow")
  186. tommy.pendown()
  187. tommy.pensize()
  188. tommy.goto(-, -)
  189. tommy.penup()
  190.  
  191. tommy.goto(-, -)
  192. tommy.color("green")
  193. tommy.pendown()
  194. tommy.pensize()
  195. tommy.goto(-, -)
  196. tommy.penup()
  197.  
  198. tommy.goto(, -)
  199. tommy.color("red")
  200. tommy.pendown()
  201. tommy.pensize()
  202. tommy.goto(, -)
  203. tommy.penup()
  204.  
  205. tommy.goto(, -)
  206. tommy.color("blue")
  207. tommy.pendown()
  208. tommy.pensize()
  209. tommy.goto(, -)
  210. tommy.penup()
  211.  
  212. tommy.goto(, -)
  213. tommy.color("#556B2F")
  214. tommy.pendown()
  215. tommy.pensize()
  216. tommy.goto(, -)
  217. tommy.penup()
  218.  
  219. # print message
  220.  
  221. bg.bgcolor("pink")
  222.  
  223. def snow():
  224. tommy.hideturtle()
  225. tommy.speed()
  226. tommy.pensize()
  227. for i in range():
  228. r=random()
  229. g=random()
  230. b=random()
  231. tommy.pencolor(r,g,b)
  232. tommy.penup()
  233. tommy.setx(randint(-,))
  234. tommy.sety(randint(,))
  235. tommy.pendown()
  236. dens=randint(,)
  237. snowsize=randint(,)
  238. for j in range(dens):
  239. tommy.forward(snowsize)
  240. tommy.backward(snowsize)
  241. tommy.right(/dens)
  242.  
  243. snow()
  244.  
  245. tommy.goto(-, )
  246. tommy.color("orange")
  247. tommy.pendown()
  248. tommy.write( "漫天 。・゚・(ノД`)ヽ(゚Д゚ ) 烟花送给你~",font=('微软雅黑', , 'normal'))
  249.  
  250. pygame.mixer.music.stop()
  251. file='media/sweet.mp3'
  252. #print("播放音乐1")
  253. track = pygame.mixer.music.load(file)
  254. pygame.mixer.music.play()
  255.  
  256. time.sleep()
  257.  
  258. tommy.penup()
  259. tommy.goto(-,-)
  260. tommy.write("祝你生日快乐哟,小寿星 ο(=•ω<=)p⌒☆!",font=('微软雅黑', , 'normal'))
  261.  
  262. time.sleep()
  263.  
  264. # send the turtle to the corner
  265.  
  266. tommy.penup()
  267. tommy.goto(-, )
  268.  
  269. #tommy.exitonclick()
  270. tommy.hideturtle()
  271.  
  272. time.sleep()
  273. tommy.clear() #清空屏幕了,然后设置背景色为黑色,滚动演员表
  274.  
  275. bg.bgcolor("white")
  276.  
  277. tommy.penup()
  278. tommy.goto(-, )
  279. tommy.color("black")
  280. tommy.pendown()
  281. tommy.write(" …(⊙_⊙;)…天呐!是不是很好看呀?坚持看到了这里",font=('微软雅黑', , 'normal'))
  282. tommy.penup()
  283. tommy.goto(-, )
  284. tommy.write(" (〃` 3′〃)那好咯,后面还有一点点结尾!",font=('微软雅黑', , 'normal'))
  285. tommy.penup()
  286.  
  287. time.sleep()
  288. tommy.goto(-, )
  289. tommy.clear()
  290. tommy.write("(python友情支持)就是我啦 ┑( ̄Д  ̄)┍ ",font=('微软雅黑', , 'normal'))
  291. time.sleep()
  292.  
  293. # tommy.clear()
  294. # tommy.write("音乐 、后期、导演、声优、编辑、构思 ",font=('微软雅黑', , 'normal'))
  295. # time.sleep()
  296. #
  297. # tommy.clear()
  298. # tommy.write("♂ 是你那不善言辞的大猪蹄子男票 ",font=('微软雅黑', , 'normal'))
  299. # time.sleep()
  300. #
  301.  
  302. tommy.clear()
  303. tommy.write("(◍•ᴗ•◍)ゝ特用此小程序祝你生日快乐~ ",font=('微软雅黑', , 'normal'))
  304. time.sleep()
  305.  
  306. tommy.clear()
  307. tommy.write("( ◜◡‾) 天天开心~ ☻ ",font=('微软雅黑', , 'normal'))
  308. time.sleep()
  309.  
  310. tommy.clear()
  311. tommy.write("最后biu 一个小心心给你把~",font=('微软雅黑', , 'normal'))
  312. time.sleep()
  313.  
  314. #这儿最后画一个小心心,
  315.  
  316. tommy.clear()
  317. #coding=utf-
  318. #画一个圆的东西出来
  319. import turtle
  320.  
  321. #turtle = tommy
  322. turtle.speed()
  323.  
  324. turtle.pensize()#:设置画笔的宽度;
  325. turtle.left()
  326. turtle.circle(,) #半径大小
  327. #画眼睛
  328.  
  329. turtle.right()
  330. turtle.forward()
  331. turtle.left()
  332. turtle.forward()
  333. turtle.right()
  334. turtle.forward()
  335. turtle.penup()
  336. turtle.goto(-,)
  337. #画眼睛了
  338. turtle.begin_fill()
  339. turtle.color("black")
  340. turtle.circle()
  341. turtle.end_fill()
  342.  
  343. turtle.penup()
  344. turtle.goto(-,)
  345. #画眼睛了
  346. turtle.begin_fill()
  347. turtle.color("black")
  348. turtle.circle()
  349. turtle.end_fill()
  350.  
  351. turtle.penup()
  352. turtle.goto(,)
  353. #画眼睛了
  354. turtle.begin_fill()
  355. turtle.color("red")
  356. turtle.circle()
  357. turtle.end_fill()
  358.  
  359. turtle.penup()
  360. turtle.goto(-,)
  361. #画眼睛了
  362. turtle.begin_fill()
  363. turtle.color("red")
  364. turtle.circle()
  365. turtle.end_fill()
  366.  
  367. turtle.penup()
  368. turtle.goto(-,)
  369. #画眼睛了
  370. # turtle.begin_fill()
  371. turtle.pendown()
  372. turtle.color("black")
  373. turtle.left()
  374. turtle.circle(,)
  375. # turtle.end_fill()
  376.  
  377. #画另一只手
  378. turtle.penup()
  379. turtle.color("black")
  380. turtle.goto(,)
  381. turtle.right()
  382. turtle.pendown()
  383. turtle.forward()
  384.  
  385. turtle.left()
  386. turtle.forward()
  387. turtle.right()
  388. turtle.forward()
  389. turtle.left()
  390. turtle.forward()
  391. turtle.right()
  392. turtle.forward()
  393.  
  394. turtle.left()
  395. turtle.forward()
  396. turtle.right()
  397. turtle.forward()
  398. turtle.right()
  399. turtle.forward()
  400.  
  401. turtle.left()
  402. turtle.forward()
  403. turtle.left()
  404. turtle.forward()
  405.  
  406. turtle.left()
  407. turtle.forward()
  408.  
  409. #爱心
  410. # turtle.begin_fill()
  411. turtle.penup()
  412. turtle.color("red")
  413. turtle.right()
  414. turtle.goto(,)
  415. turtle.pendown()
  416. turtle.circle(,)
  417. turtle.forward()
  418. turtle.left()
  419.  
  420. turtle.forward()
  421.  
  422. turtle.penup()
  423. turtle.color("red")
  424. turtle.right()
  425. turtle.goto(,)
  426. turtle.pendown()
  427. turtle.circle(-,)
  428. turtle.forward()
  429. turtle.right()
  430.  
  431. turtle.forward()
  432.  
  433. # turtle.end_fill()
  434.  
  435. turtle.penup()
  436. turtle.goto(,)
  437. turtle.pendown()
  438. # turtle.right()
  439. turtle.forward()
  440. turtle.left()
  441. turtle.forward()
  442. turtle.right()
  443. turtle.forward()
  444. turtle.goto(,)
  445.  
  446. turtle.penup()
  447. turtle.goto(-,-)
  448. turtle.write("The end",font=("微软雅黑",,"normal"))
  449.  
  450. time.sleep()
  451.  
  452. done() #可以使窗口保持
  453.  
  454. pygame.mixer.music.stop()

理解完成之后想要在自己的笔记上面跑起来:结果出了好几个小小的问题

问题1:我安装是Python3.6.3的版本,但是直接运行程序的话提示没有pygame 模块,所以自己就在自己Pycharm中进行下载,但是搜索都搜索不到,所以就到cmd中去利用pip命令去安装了

pip命令去安装:

下载地址:https://pypi.org/

搜索pygame,转到pygame1.9.6之后点击pygame1.9.6,然后转到另一个界面

转到下面的界面,之后选择cp36的下载即可,因为自己安装的python是64位的,所以下载了最后一个pygame-1.9.6-cp36-cp36m-win_amd64.whl

由于自己的之后黑窗口安装

打开cmd命令窗口,通过“pip install"命令安装pygame安装包。当然的pip命令最好是在whl文件所在的目录下面,这样的话可以输入几个开头字母之后自动补全

  1. pip install pygame-1.9.6-cp36-cp36m-win_amd64.whl

检测是否安装成功,在cmd命令窗口下,输入”python“,进入python交互命令窗口,输入”import pygame“,如果运行成功,表示安装成功。

之后运行成功

最后想要到别的电脑上也能够运行,所以就想将程序打成exe可执行程序

接下来说干就干

大家都知道,Python是一种脚本语言,也就是解释型的语言,需要解释器来进行解释以后才可以执行,而Python源代码需要在Python虚拟机上面运行,但是我们做好的程序,不可能给用户使用的时候还让他安装一个Python环境,所以今天我们讲解如何将Python程序打包为exe可执行文件。

提示: 以下的教程都是再有Python环境的基础上的,如果没有安装,请先参考:Python安装以及环境变量配置

一、安装pyinsatller

打开命令行窗口,输入如下指令

pip3 install pyinstaller

然后静待pyinstaller自动安装好

但是自己在安装pyinstaller的过程中出现了问题

问题解决加上参数     --no-use-pep517

  1. pip3 install pyinstaller --no-use-pep517

成功的安装了  输入pyinstaller  --version去验证是否成功,显示版本也就是成功了

如果还未解决的话,可以继续的参考链接解决哦   https://blog.csdn.net/qq_26561157/article/details/89812450

二、使用pyinstaller打包Python程序(参考链接https://blog.csdn.net/qq_33462307/article/details/90479045

①在你的Python程序文件夹上(不点进去)按住shift并且右键,在弹出的选项中点击"在此处打开命令行窗口"或者“在此处打开PowerShell窗口”

在上面的目录下按住shift 之后右键选择打开powershell

下面的是自己的界面:

>>>或者先进入命令行窗口,然后使用cd指令进入程序文件夹,示例:

cd E:\课件\python数据分析与数据挖掘\数据挖掘方法及应用\Python数据挖掘\程序\Gp201820192\BigData\BirthdayFinal

②输入以下指令,开始打包

pyinstaller -F -w (-i icofile) filename

filename表示你的Python程序文件名

-w 表示隐藏程序运行时的命令行窗口(不加-w会有黑色窗口)

括号内的为可选参数,-i icofile表示给程序加上图标,图标必须为.ico格式    icofile表示图标的位置,建议直接放在程序文件夹里面,这样子打包的时候直接写文件名就好

具体的将文件改为.ico格式的工具网站  http://www.bitbug.net/

接着   pyinstaller -F -w (-i icofile) filename   命令输入完成,按回车,就会开始自动打包了,第一次打包过程可能比较缓慢

输入示例:

pyinstaller -F -w  -i birth.ico  Birthday.py

(pyinstaller中的各个参数的含义:https://blog.csdn.net/weixin_39000819/article/details/80942423

打成exe成果的效果

然后我们进入到程序目录里面会再看到一个名称为dist目录,打包好的exe程序就在里面

注意:如果原本的程序中使用到了相应的资源,需要复制到dist目录下,否则程序会无法运行

比如我这里在程序中使用到了好多的音频,所以就需要将该文件放到dist目录下,我这里是在dist目录下新建了一个目录:media,把那些文件放了进去

形成exe目录在之后的结构

最后进入到自己的dist目录下,点击exe程序即可启动程序,具体的程序效果可见链接  https://www.bilibili.com/video/av53114885

如果点击exe程序,出现错误弹出框

Pygame使用pyinstaller打包exe无法运行,显示 failed to execute script的问题

原因剖析

pygame需要的资源如图片音乐等pyinstaller是不会给你打包的,需手动加入

本来自己用pyinstaller 形成的dist命令是没有依赖的那些mp3和图片等文件的,自己需要去加入到和exe一样的dist目录下,如果不加入的话会提示   failed to execute script

python生日贺卡制作以及细节问题的解决最后把python项目发布为exe可执行程序过程的更多相关文章

  1. 【5号课堂】scratch制作电子生日贺卡

    贺卡在我国的使用由来已久,在古代,上层士大夫有用名帖互相问候的习俗 唐宋以后,贺卡的名称及功能有所进步,称为”门状“或“飞帖“,到了明清,又叫“红单“.“贺年帖“等等,听着名字就知功能越来越世俗化,文 ...

  2. 实战微信JS SDK开发:贺卡制作与播放(2)

    最近同事用CanTK开发了一个基于微信的贺卡制作APP,我虽然没有参与开发,但是提供CanTK和GameBuilder的技术支持,觉得有些东西比较有意思,写几篇博客和大家分享吧.这个贺卡APP完全开源 ...

  3. 实战微信JS SDK开发:贺卡制作与播放(1)

    前段时间忙于CanTK 2.0的开发,所以博客一直没有更新.CanTK 2.0主要增强了游戏和富媒体的开发,现在编码和测试基本完成了,等文档完成了再正式发布,里面有不少激动人心的功能,等发布时再一一细 ...

  4. python socket编程制作后门木马(原创)

    不知道为啥,懒得解释怎么写出来的,直接上代码,爱看不看 Client:  简单连接服务器 #!/usr/bin/python #coding:utf-8 import socket import sy ...

  5. 制作属于自己的翻译软件(基于PyQt5+Python+实时翻译)

    目录 制作属于自己的翻译软件(基于PyQt5+Python+实时翻译) 翻译软件上传到github上. 软件截图 主要的思想 界面方面 程序方面 制作属于自己的翻译软件(基于PyQt5+Python+ ...

  6. 手摸手教你如何在 Python 编码中做到小细节大优化

    手摸手教你如何在 Python 编码中做到小细节大优化 在列表里计数 """ 在列表里计数,使用 Python 原生函数计数要快很多,所以尽量使用原生函数来计算. &qu ...

  7. pyinstaller使用-python项目转换成exe可执行文件

    http://blog.csdn.net/pipisorry/article/details/50620122 Python不是每个人的计算机里面都有安装,当您写了一个好用的工具,需要一个standa ...

  8. Python学习教程(十)精选 TOP45 值得学习的Python项目

    精选 TOP45 值得学习的Python项目 [导读]热门资源博客 Mybridge AI 比较了 18000 个关于 Python 的项目,并从中精选出 45 个最具竞争力的项目.我们进行了翻译,在 ...

  9. <小白学技术>将python脚本导出为exe可执行程序

    1.简介(为啥需要导出为exe可执行程序) python写完的程序靠命令来执行,显得太专业,不符合python简单的特点(好吧,主要是太low) 代码给别人执行,别人没有你的python库也没法用(双 ...

随机推荐

  1. webpack4.0 ---引用vue文件

    一.引入Vue 1.安装依赖环境 npm i vue-loader -D;//解析转化.vue文件,npm i vue-style-loader -D npm i vue-template-compi ...

  2. Iptables和Firewall-selinux

    一.Iptables防火墙 ---------- **三表五链:**三表: filter过滤表 nat转换表 mangle表五链: PREROUTING--->在进行路由选择前处理数据包 INP ...

  3. No

    1.为什么A/D转换前需要采样保持电路,它的基本原理是什么? 因为被取样的信号是动态,随时改变的,而A/D转换需要时间,在这个转换的过程中,信号是变化的,为了弥补A/D转换的时间差,所以需要采样保持. ...

  4. POJ_2941_矩阵

    题目描述: 每组数据给定一个n*n的矩阵,选定不同行不同列的n个元素,求和,若所有选法所产生的和相等,则输出 homogeneous,否则输出not homogeneous. 描述: 数据挺大,爆搜肯 ...

  5. Codeforces 1050D Three Religions (dp+序列自动机)

    题意: 给一个1e5的串str,然后有三个起始空串,不超过1000次操作,对三个字符串的一个尾部加一个字符或者减一个字符,保证每个字符不会超过250 每次操作之后询问你这三个串是不是可以组成str的子 ...

  6. BZOJ 1025 [SCOI2009]游戏 (DP+分解质因子)

    题意: 若$a_1+a_2+\cdots+a_h=n$(任意h<=n),求$lcm(a_i)$的种类数 思路: 设$lcm(a_i)=x$, 由唯一分解定理,$x=p_1^{m_1}+p_2^{ ...

  7. 基于CentOS-7 部署open

    一.OpenVPN概述 OpenVPN是一个用于创建专用网络加密通道的源软件.可在公司和家庭之间.部署类似于局域网的专用网络通道 而且OpenVPN使用起来也非常方便.几乎可以运行在任何平台.同时也采 ...

  8. Property - 特性(Python)

    Property - Python 特性 不同的书籍对 property 一词的翻译有所不同, 我们将 property 翻译成 '特性' 以区别于 attribute 一词. 先看看 propert ...

  9. Maven项目pom文件的节点释意

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  10. XLNet:运行机制及和Bert的异同比较

    这两天,XLNet貌似也引起了NLP圈的极大关注,从实验数据看,在某些场景下,确实XLNet相对Bert有很大幅度的提升.就像我们之前说的,感觉Bert打开两阶段模式的魔法盒开关后,在这条路上,会有越 ...