turtle module python code example

Example 1: how to make a screen in turtle

def turtle_triangle():
    window = turtle.Screen()
    window.bgcolor("red")
    
    brad = turtle.Turtle()
    
    brad.shape("turtle")
    brad.color("yellow")
    brad.speed(1)

    for _ in range(3):
        brad.right(60)
        brad.forward(200)
        brad.right(60)

    window.exitonclick()

Example 2: 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 3: how to import turtle in python

import turtle

Example 4: python turtle

import turtle
tina=turtle.Turtle()
#trinket.io specializes in these stuff

Example 5: python turtle example

# Step 1: Make all the "turtle" commands available to us.
import turtle

# Step 2: Create a new turtle. We'll call it "bob"
bob = turtle.Turtle()

# Step 3: Move in the direction Bob's facing for 50 pixels
bob.forward(50)

# Step 4: We're done!
turtle.done()

Example 6: turtle module python

>>> player_one = turtle.Turtle()
>>> player_one.color("green")
>>> player_one.shape("turtle")
>>> player_one.penup()
>>> player_one.goto(-200,100)
>>> player_two = player_one.clone()
>>> player_two.color("blue")
>>> player_two.penup()
>>> player_two.goto(-200,-100)

Tags:

Misc Example