Home >Backend Development >Python Tutorial >How to install turtle in python

How to install turtle in python

(*-*)浩
(*-*)浩Original
2019-07-03 14:43:3125680browse

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.

How to install turtle in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn