Learn to Code via Tutorials on Repl.it!

← Back to all posts
Python Turtle Tutorial!
SamiOsman

Hi Everyone!

my friend @JWZ6 and I will be teaching you Python Turtle today! I am new to tutorials so I hope this helps! (Me and My friend @JWZ6 working really hard on this so please upvote if you like it!)

Here is the link to his post go upvote it!
This is definitely not boring (100% true).

Table Of Contents

  • Getting Started
  • Turtle Movement
    • Drawing
      • Introduction
      • Circles And Dots
      • Stamp
      • Making Polygons
    • Positioning
      • Goto
      • Setposition
    • Writing
  • Drawing
    • Color
    • Filling
      • Begin Filling
      • End Filling
    • Pen Visibility
      • Show Turtle
      • Hide Turtle
    • Other Drawing Methods
      • Turtle Speed
      • Turtle Shape
      • Turtle Size
      • Turtle Pen Color
  • Events
    • Onkey
    • Ontimer
    • Onclick
      • Python
      • Python(with Turtle)
  • Window
    • Background
      • Bgcolor
      • Bgpic
      • Reset
    • Input
      • Text Input
      • Number Input
    • Exiting
      • Exit
      • Exit Onclick
    • More Window Methods
      • Setup
      • Title
    • Ending

Getting Started

First, open up a new project. You can do it in either Python or Python(with Turtle). Next, do:

The turtle.title() won't work if your using Python(with Turtle). You can rename the turtle title. Just be careful and don't get any errors.

Turtle Movement

Drawing (Introduction)

Lets start off by doing turtle.forward(30). This will make the turtle move forward. The number in the () is the amount you want it to go forward. You also have turtle.backward(), turtle.left(), turtle.right(), turtle.up(), and turtle.down. No need for an explanation on how they work. For example, you could have:

Negatives also work. The numbers inside the () have to be integers or floats. No strings

Drawing (Circles And Dots)

If you want a circle, do turtle.circle(radius). The radius of the circle goes inside the (). If you use turtle.dot(radius, color), you would get a dot. The differences between the circle and the dot are that the dot would be filled by the color, but the circle wouldn't be. The middle of the dot is the turtle cursor, but the edge of the dot is the cursor. For example, you might have:

Drawing (Stamp)

By using turtle.stamp(), you imprint the turtle shape onto the turtle canvas, whether it's triangle or classic (I'll get to that later). If you don't want the stamp, just don't use it. It looks like this:

Making Polygons

To begin a polygon, use turtle.begin_poly(). To end one, use turtle.end_poly(). I'm not exactly sure why there's a begin/end polygon function. If you use it, do:

Position

You can position the turtle pen by using turtle.goto(). or you can use setposition(). They're the same thing. By using turtle.goto() , the turtle pen will teleport the turtle to the exact coordinates that you give inside the (). If you put two coordinates then do x, y. Remember, x comes first, not y. For example, you could have:

Writing

You can write text by using using turtle.write("text"). For example, you could have:

Drawing

Color

You can change the color by using turtle.color(color). That way you can change the turtle color while you are drawing. Look to Turtle Movement for how to do that. For example, you might have:

Filling

(You have to make a shape before the shape can be filled).

You can start filling by using turtle.begin_fill(). You end the filling by doing turtle.end_fill(). The last color you use before the turtle.end_fill() will be the fill color. For example:

Pen Visibility

You can either hide the pen or show the pen in Python Turtle. You can hide the turtle pen by using turtle.hideturtle(). Use turtle.showturtle() to show the pen. For example, you might use:

Other Drawing Methods

Turtle Speed

You can change the speed of how quick the turtle pen is moving by using turtle.speed(). The number range inside the () has to be 0-10. 0.5-0 shows no movement unless you change the turtle speed later on. 1 means very slow while 10 means fast. For example, you could have:

Turtle Shape

There are 6 different types of turtle shapes: classic, arrow, square, circle, triangle, and turtle. You can use those shapes in turtle.shape(shape). For example, you could have:

Turtle Drawing Size

You can change the turtle drawing size by using turtle.pensize(). The number inside the () must be in between 1-10. 1 is very thin but 10 is thick. For example, you might have:

Turtle Pen Color

You can change the pen color by using turtle.pencolor(""). In the quotation marks put the color that you want the turtle to be. This will not change the drawing color, only the pen color. For example you could have:

Events

Onkey

This will not work for mobile or Python(with Turtle)

Using turtle.onkey(function, "key") will detect if a number, arrow key, or letter is pressed. For arrow keys, use "Up", "Down", "Left", and "Right". This does not work for other keys (like space). The same works for numbers. You could have:

You must end with a turtle.listen() to make onkey work.

Ontimer

This only works in Python

turtle.ontimer(function, t=0) means that it executes the function after the t = (t in milliseconds). You don't need to use turtle.listen(). For example you could have this:

Onclick

Python

By using turtle.onclick(function (), btn=1, add=None). It will execute the function(). btn=1 means the number of times the user has to click in order to execute the function. add=None means that if it is True, a new binding will be added, and if it is False it will replace a former binding. For example you could have:

Python (with Turtle)

Using onclick in Python(with Turtle) is simpler than using onclick in Python. The syntax looks like turtle.Screen.onclick(function). For example, you might have

Window

Background

This does not work for Python(with Turtle)

By using turtle.bgcolor("color"), you create a background of the color. You can also create an image background by using turtle.bgpic("img.png"). The img.png is just an example. GIF's do not work. You could have

To reset all the drawings, use turtle.reset(). The background will still be the same, though.

Input

This also does not work for Python(with Turtle)

For a text input, use turtle.textinput("title", "question"). For a number input, use turtle.numinput(). By using minval and maxval, you create a minimum value for the number and a maximum value for the number. For example, you could have:

Exiting

If you want to exit very quick, use turtle.bye(). If you want to exit onclick, do turtle.exitonclick(). For example, you can have:

More Window Methods

Setup Size

This does not work in Python(with Turtle)

You can change the setup by using turtle.setup(). There are 4 attributes: width, height, startx, and starty. The width and height are self-explanatory. Using startx will make the starting position align more to the left. The starty attribute does the opposite. You might have:

Title

This also does not work in Python(with Turtle)

I already talked about title in the very beginning. The syntax is turtle.title("title"). For example, you can have:

Ending

This took me and my friend @JWZ6 4 days to write! I hope you found this useful. If you did, make sure to upvote. (btw I am new to tutorials) Anyways, I'm done!

Bye!

Voters
ed0913
JWZ6
nighthowler422
ahmedo123454
Th3Coder
ch1ck3n
SamiOsman
Comments
hotnewtop
ahmedo123454

not that bad

ahmedo123454

cool

SamiOsman

@ahmedo123454 Thx! I just wish more people would see it.