turtle庫是Python語言中一個很流行的繪制圖像的函數庫,想象一個小烏龜,在一個橫軸為x、縱軸為y的坐標系原點,(0,0)位置開始,它根據一組函數指令的控制,在這個平面坐標系中移動,從而在它爬行的路徑上繪制了圖形。
安裝turtle(推薦學習:Python視頻教程)
Python2安裝命令:pip install turtule
Python3安裝命令:pip3 install turtle
繪圖舉例
太陽花import turtle as timport time
t.color("red", "yellow")
t.speed(10)
t.begin_fill()for _ in range(50):
t.forward(200)
t.left(170)
end_fill()
time.sleep(1)
繪制五角星import turtleimport time
turtle.pensize(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()for _ in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
time.sleep(2)
turtle.penup()
turtle.goto(-150,-120)
turtle.color("violet")
turtle.write("Done", font=('Arial', 40, 'normal'))
time.sleep(1)
更多Python相關技術文章,請訪問Python教程欄目進行學習!
以上就是python怎么安裝turtle的詳細內容,更多請關注php中文網其它相關文章!
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!