Setting up Turtle

In order to use Turtle in Python we must first import the Turtle library. By default we don't load all of the features Python has, this reduces the amount of memory our programs use. If we forget to include the library then our programs will crash.

import turtle

We must import Turtle before we use any of the functions included in the library, however most people will simply import it at the top of their Python file. 

As soon as we have imported Turtle we can start programming but there are a few set-up options we can work with. 

Screen size

We can set up our drawing environment by adjusting the screen size. This is useful if you need more space for your drawings or want to customize the drawing area to fit a specific size.

screen = turtle.Screen()
screen.setup(width=800, height=600)

In this example, the screen is set to 800 pixels wide and 600 pixels high. We can adjust these values if needs be.

Turtle attributes

We can also use variables to set the turtle's attributes, such as its shape and color. This makes our code more flexible and easier to modify.

my_turtle = turtle.Turtle()
my_turtle.shape("turtle")
my_turtle.color("red")

In this example, the turtle's shape is set to "turtle", and its color is set to blue. You can choose from several shapes such as "arrow", "circle", "square", "triangle", and "classic".


Included in the following specifications:
KS3 Computing