Home >Backend Development >Python Tutorial >How to install turtle in python
The turtle library is a very popular function library for drawing images in the Python language. Imagine a little turtle, starting at the origin of a coordinate system with the horizontal axis x and the vertical axis y, (0,0), and it starts at the (0,0) position. The control of a set of function instructions moves in this plane coordinate system, thereby drawing graphics on the path it crawls.
Install turtle (Recommended learning: Python video tutorial)
Python2 installation command:
pip install turtule
Python3 installation command:
pip3 install turtle
Drawing example
Sunflower
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)
Drawing five-pointed star
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)
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to install turtle in python. For more information, please follow other related articles on the PHP Chinese website!