python turtle module documentation code example

Example 1: how to import turtle in python

import turtle # imports it
whateverYouWantToCallIt = turtle.Turtle() # adds it to the project
#code
whateverYouWantToCallIt.forward(10) # moves whateverYouWantToCallIt forward
whateverYouWantToCallIt.color("purple") # color
whateverYouWantToCallIt.left(90) # turns him 90 degrees
whateverYouWantToCallIt.right(90) # turns him 90 degrees the other direction

Example 2: how to import turtle in Python

import turtle
win = turtle.Screen()

Example 3: turtle graphics in python

from turtle import *
color('red', 'yellow')
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()

Example 4: how to import turtle in Python

import turtle
win = turtle.Turtle()

Example 5: how to setup Turtle python

import turtle
win = turtle.Screen()
win.bgcolor("black")
win.setup(Height=800, length=500)
win.title("setup")