程序简略代码如下:

 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()

输出图片如下:

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

用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:不用理会。

 

相关文章:

  • 2021-07-06
  • 2022-12-23
  • 2021-08-20
  • 2021-06-12
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2021-07-28
  • 2022-02-04
  • 2021-12-12
  • 2022-12-23
  • 2021-11-20
  • 2021-10-28
相关资源
相似解决方案