Learn to Code via Tutorials on Repl.it!

← Back to all posts
Python Turtle Module Tutorial 1

Python Turtle

Welcome to my first python module simple tutorial, this lesson I will teach you the basics of turtle visuals, like if you want to see part 2, it would tell me if someone reads this tutorial.


So in turtle you can create games, simple games but it is still amazing, first of all, import turtle.

Setting up

In turtle the command "turtle.Screen()" can change the title, backround color and more, so first shorten it by doing:
wn = turtle.Screen()
You do this so you don't have to write it a lot, you just write 2 letters, your code should look like this:

so now we don't have to write turtle.Screen()
just wn to say it

Screen backround color

in order to change the backround color, you need to do:

bgcolor means backround color, and it doesn't need to be green, it can be red, yellow and more.

Now that you run it, you will see a green backround, that is it, but it is really small, how do we make it bigger?

Screen size

The highest height of a screen can be 800, and width 600, I will explain why later on.

we write this so we don't have to write 800 and we can use the height or width later on.
next write:
wn.setup(height, width)
the height is 800 and width is 600, you can write 800 there but it will be easier for you later on, setup basically means the screen size, the max height is 800 and width is 600 is because if you put it higher, part of the screen will be blocked, you can test it out.


The title isn't really that important but you can use it, if you did the setup on repl.it, you won't see it, but you will if you use python IDE.
you do "wn.title("Put a title here")
your code should look like this:

Draw a shape

We finished the turtle screen, Yay!
now how about we draw a square?
we can't use the turtle.Screen() for the command to draw or place objects and shapes, so we need to use "turtle.Turtle()" it is a command where it is literally a pen, if you make it go forward, it draws where it goes, or you can make it not draw, or with it you can create a character than can move, so first lets do:

When you run the code, you should see an arrow on your screen, that is a good sign, that is the pen, you can see where it moves, you can also hide it so you can't see it, I will tell you how later on.
to make it draw you need to make it move, how to do that? It is pretty simple, you do:
pen.forward(100) forward is it going forward where it is facing and the 100 is how much pixels it will move, your code should look like this:

Now run it, you should see a line, it was facing right of the screen so it moved forward to the right, but how to turn it left so we can make a square? Simple.
You do:
it will turn left but it won't go to the left, then you can make it go forward again, try to make a square now, if you don't know how, I will show you:

Scroll down for the answer

The answer is:

the advanced way is:

for i in range(4) means it will do that command 4 times

Want to know how to fill the square?
before the code where you do "pen.forward(100)"
write "pen.begin_fill"
and after the last code of it drawing a square write
Also if you don't want your pen to draw while it is going somewhere, write "pen.penup()" and when you want it to draw, write "pen.pendown()"
and if you want the triangle to dissappear write "pen.hideturtle()"

Want to know how to change the color?
To do that you do "pen.color("blue")
Doesn't need to be blue
#Creating Shapes
In order to create a shape, it is simple, you do:
Do you want your shape to be bigger

the first 2 are the height and width, and the 3rd is outline size.
I think that is it, if there is an error, then repl.it glitches turtle sometimes, don't add new files to your code, it does work on python IDE perfectly though, if you got an error, comment the link of your repl and I will reply within 24 hours, also like if you want part 2, it tells me if people are actually reading this, I will show you what turtle can do.

That is only the scratch of the surface though.


Perhaps use code blocks?
This is a code block

This is a code block with syntax


@CodeLongAndPros Yeah, more people need to use markdown.


@CodeLongAndPros Ok, thanks.


@CodeLongAndPros I am new to making tutorials, but I got it now thanks to you.




@lyrical Thanks, also I checked your python turtle repl, you saw that when you drew a square, the first line is black, the reason is that you put:

but you need to do:

also you placed this code in the wrong position

and on pen.end_fill()
you need brackets at the end.
Also the pen.end_fill needs to be out of the for loop
so after it completed the foor loop, that when you want it to finish.
Your code should look like this:

If you got any more questions, ask here, I will answer within 24 hours, if you are intrested in turtle and get the first tutorial, here is the 2nd tutorial.


Turtleee. Thanks for this.


@PsyPy, No problem, hope it helped :)


@PsyPy I will do a part 2


that advanced way is not working ..... remain everything working


Screen size did not work in repl.it but did work in python IDE.


@adrianmccall10 make sure you don't add any files other than sprites, or it will glitch


@adrianmccall10, and I don't use python turtle repl, I just use python then I import turtle


@adrianmccall10 to fix the problem, you make a new repl


good good thanks sans