新学python画一个爱心,并用pyisntaller打包为可执行exe文件


程序简略代码如下:

 1 from turtle import *
 2 def curvemove():
 3     for i in range(200):
 4         right(1)
 5         forward(1)
 6 color('yellow','red')
 7 begin_fill()
 8 left(140)
 9 forward(111.65)
10 curvemove()
11 left(120)
12 curvemove()
13 forward(111.65)
14 end_fill()
15 done()

输出图片如下:

用pyinstaller将上述程序打包得到的可执行文件可以在没有安装python环境下执行。

方法如下:

cmd下安装pyinstaller库

pip install pyinstaller

然后找到上述代码的文件目录,例如:C:\Users\Benny\Desktop\Python\Python练习\heart_shaped_picture.py

在cmd下相继执行下列语句:

pyinstaller C:\Users\Benny\Desktop\Python\Python练习\heart_shaped_picture
pyinstaller -F C:\Users\Benny\Desktop\Python\Python练习

命令执行会在根目录下生成两个文件夹build和dist,build记录一些日志log,heart_shaped_picture.exe生成在dist文件夹内。

如果上述代码运行结束时出现PermissionError:不用理会。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM