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
and close that out with import turtle
at the end. turtle.done()
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-4.34.33-PM-1.png)
Next, right under
make a new instance of a turtle like so (the second turtle uses a capital T): import turtle
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:
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-4.41.16-PM.png)
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:
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-4.43.42-PM.png)
If you wrap your code with a
and kitten.begin_fill()
, the square will turn blue at the end of the animation. kitten.end_fill()
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-4.49.58-PM.png)
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-4.46.58-PM.png)
You can make the border cyan and the fill pink like so:
kitten.color("cyan", "pink")
![](https://kittenkamala.com/wp-content/uploads/2019/09/Screen-Shot-2019-09-19-at-5.11.52-PM.png)
It’s cute! Hooray! We can draw a square! We just made it through our first day of Python Preschool. Woot!