当前位置:   article > 正文

python使用turtle画雪花,以及使用pyinstaller打包程序_pyinstaller库打包turtle代码

pyinstaller库打包turtle代码

我们使用科赫曲线来画画雪花,主要是无聊
过程很简单,理解思路就行

import turtle
import time
times=time.perf_counter()
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():
    global times
    turtle.setup(600,600)
    turtle.penup()
    turtle.goto(-200,100)
    turtle.pendown()
    turtle.pensize(2)
    level=4   # 这是是科赫曲线的数量
    koch(400,level)
    turtle.rt(120)
    koch(400,level)
    turtle.rt(120)
    koch(400,level)
    turtle.hideturtle()
    print("画图所用时间时间{}秒!".format(time.perf_counter()-times))
    turtle.done()

main()

print("程序运行时间{}秒!".format(time.perf_counter()-times))
input('按Enter关闭窗口!!!')


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

这里还使用了time库,用来计算程序运行的时间
最后可以把这个程序用pyinstaller打包成一个可执行的exe文件
这样就可以在没有python环境的电脑运行啦!!!
然后把它发送你们的朋友看看哈哈哈哈哈

先使用下面命令安装pyinstaller库

pip install pyinstaller
  • 1

然后就可以打包python程序了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/710193
推荐阅读
相关标签
  

闽ICP备14008679号