程序簡略代碼如下:
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:不用理會。