Python Turtle Basics v 1

The Turtle module in Python allows you to draw with code. Woot!

Of course you’ll need to have Python installed on your local machine.

You’ll likely want to work with a code editor, of course, most of which support Python graphics. I use VSCode.

Step 1: Create a file with the extension .py on the end. Open it in your editor. Okay, that is two steps. (>.>).

Now you’ll want to make sure you include the turtle module with import turtle and close that out with turtle.done() at the end.

Next, right under import turtle make a new instance of a turtle like so (the second turtle uses a capital T):

kitten = turtle.Turtle()

Then you can go ahead and tell it to move!

Draw a line forward 100 pixels:

kitten.forward(100)

Turn left 45 degrees:

kitten.left(45)

Turn right 90 degrees:

kitten.right(90)

Seems pretty logical, right?

Here is how we can make a square:

Make the turtle and line a color:

kitten.color("cyan")

Or you could even use an RGB or hex value:

kitten.color("#ffffff")

If you make it cyan it will look like this at the end of the animation:

If you wrap your code with a kitten.begin_fill() and kitten.end_fill(), the square will turn blue at the end of the animation.

You can make the border cyan and the fill pink like so:

kitten.color("cyan", "pink")

It’s cute! Hooray! We can draw a square! We just made it through our first day of Python Preschool. Woot!

Leave a Comment