PyInstaller库--turtle画图使用ico图片打包成.exe可执行文件

 pip install pyinstaller 安装模块

(命令行)pyinstaller  -F <文件名.py>  生成独立文件  (建议使用)

          -h  帮助

          --clean  清理临时文件

         -D   默认值,生成dist文件夹

        -i <图标文件名.ico>  指定打包程序使用的图标

import turtle
def koch(size,n):
    if n==0:
        turtle.fd(size)
    else:
        for angle in [0,60,-120,60]:
            turtle.left (angle)
            koch(size/3,n-1)
def  main():
    turtle.setup(600,600)
    turtle.penup()
    turtle.goto(-200,100)
    turtle.pendown ()
    turtle.pensize(2)
    level=3
    koch(400,level)
    turtle.right (120)
    koch(400,level)
    turtle.right (120)
    koch(400,level)
    turtle.hideturtle()
main()

将py文件和ico图标放在一个文件夹,通过pyinstaller -f  文件名.py  -i 图标文件名.ico 生成可执行文件

如下图所示:

 进入所在文件夹后,执行命令

 看见successfully就是成功啦,刚才的文件夹里多了很多文件了哦!

在dist中可看见我们想要的exe文件,就是我们萌萌的小鸟

双击执行可出现程序画图效果

 搞定啦!

猜你喜欢

转载自www.cnblogs.com/renxiaoyan/p/10958013.html