Learn to Code via Tutorials on Repl.it!

← Back to all posts
A Crash Course In Python Turtle!
h
JWZ6

Hi Everyone!

Me and @SamiOsman will be teaching you Python Turtle today! I've seen many Python Turtle tutorials and they aren't exactly the best. Anyways, here it is! A good Python Turtle tutorial is here.

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, wether 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 @SamiOsman 4 days to write! I hope you found this useful. If you did, make sure to upvote. Anyways, I'm done!

Bye!

P.S If I have any grammar mistakes, please tell me so I can fix them. Also, make sure to check out @SamiOsman 's post: https://replit.com/talk/learn/Pyhton-Turtle-Tutorial/138758
Voters
ed0913
TGC303
programmeruser
bensonSucccess
AJAYUPPU
GonzaloSilva2
pepss
KubaLewandowski
JrCodingChamps
ahmedo123454
Comments
hotnewtop
ahmedo123454

this is what it is like bruhhhhhhhhhhh

JWZ6
byronordolol
JWZ6

@byronordolol um ok this is not a rickroll

byronordolol

@JWZ6 ok lol

JWZ6

it's quite obvious it's not a rickroll lol @byronordolol

byronordolol

ok boomer @JWZ6

JWZ6
byronordolol

@JWZ6 literally oneperson recognizes the comedy of the 'ok boomer' how do i do strikethrough

JWZ6

@byronordolol lol use ~~ to start and end text in strikethrough

byronordolol

@JWZ6 thanks

JWZ6
byronordolol

@JWZ6 squiggle be like ~

JWZ6
byronordolol

@JWZ6 im gonna test strikthru since am new lol ~xD~

JWZ6

@byronordolol u need 2 of those

byronordolol

@JWZ6 oh like dis?

JWZ6

@byronordolol yup congrats

byronordolol

@JWZ6 thanks lol me when week 7 in fnf

JWZ6
byronordolol

@JWZ6 when human go bonk: D:

JWZ6

@byronordolol lolololololololol

byronordolol

@JWZ6 beeep boop bap bep bop

JWZ6

@byronordolol boyfriend goes brrrrrrr

byronordolol

@JWZ6 me when zZHXYASuhdweiusgudghi7slgweuyuguhs67wrfsrewdsdssadswdsdwsdawsasdsawdadcaswdasdadswsrtfryttegystrtokenuhuegfgesugeugsugsygyqgswdsdQ

JWZ6
byronordolol

@JWZ6 stroke lol

JWZ6
byronordolol

@JWZ6 basicall my only online friend lol what seems to be odd is that nobody expects replit to be a place where u can chat with people lol

JWZ6
byronordolol

@JWZ6 im bored

JWZ6

@byronordolol everyone is

byronordolol

@JWZ6 plus i got school and assignments to complete

fel1x0u

This is cool. But I would recommend also teaching turtle.tracer() alongside turtle.speed.

JWZ6

@fel1x0u hmmm, I might do a part 2, though not sure

codermaster8

👎 Not working

This is not working I’m doing it but it does not work I can’t make it draw

JWZ6

@codermaster8 you must first import turtle

codermaster8

I did do that @JWZ6

JWZ6

@codermaster8 which part doesn't work?

codermaster8

The drawing @JWZ6

JWZ6

@codermaster8 like turtle.forward or something

JWZ6

@codermaster8 this has to be python or python(with Turtle)

codermaster8

yeah it says there is an error so what should I do @JWZ6

codermaster8

I did that @JWZ6

JWZ6

@codermaster8 well, try ctrl + c, ctrl + v some of my codeblocks i guess

JWZ6

@codermaster8 which error r ya getting

codermaster8

nevermind i got it to work maybe cause on my tablet it does not work @JWZ6

JWZ6

@codermaster8 hmm could be anyways yay! glad it works

codermaster8

:) @JWZ6

JWZ6
codermaster8

I never knew but python (with turtle) doesn’t work but just regular python turtle works on my tablet @JWZ6

JWZ6

@codermaster8 huh weird

codermaster8

Lol @JWZ6

JWZ6
codermaster8

Oh now it doesn’t work lol @JWZ6

JWZ6
codermaster8

Lol i dont know why but now it’s working it’s like changing @JWZ6

JWZ6
codermaster8

This is my double square

Hope ya like it @JWZ6

JWZ6
codermaster8

Thx @JWZ6

JWZ6
Th3Coder

NOICE!

I prefer using HTML, CSS, and JS instead of Turtle though
JWZ6
Th3Coder

@JWZ6 to be honest, this is literally the fastest I've seen a post go trending, congrats!

JWZ6

@Th3Coder lol thx

JWZ6

@Th3Coder this went to trending in less than a minute LOL

Th3Coder

@JWZ6 you deserve a place in The Guinness Book of World Records!

JWZ6

@Th3Coder LOLOLOLOLOL

ch1ck3n

pog

ch1ck3n

@ch1ck3n wow fastest reply ever

JWZ6

@ch1ck3n LOL Congrats

JWZ6

@ch1ck3n just got ya 1,700 cycles

ch1ck3n

@JWZ6 yay

JWZ6

@ch1ck3n glad u like me tutorial also yay too

ch1ck3n
JWZ6
ch1ck3n

@JWZ6 ya just got rick rolled

JWZ6

@ch1ck3n lol x-d out before it could

ch1ck3n

@JWZ6 oop

JWZ6
Th3Coder

@ch1ck3n thank you for blessing me with this link

ch1ck3n

@Th3Coder no problem

JWZ6
ch1ck3n

@Th3Coder

at least i have this

JWZ6
Th3Coder

@ch1ck3n poggest?

JWZ6

@Th3Coder hmmmmmmmmmm

ch1ck3n

@JWZ6 @Th3Coder give me a coding challenge for a website

JWZ6
JWZ6

@ch1ck3n also y am i gettin 10 notifs every 2 min?

Th3Coder

@ch1ck3n easy, hard, or impossible?

ch1ck3n

@JWZ6 this post is this morning's #general for us

ch1ck3n
ch1ck3n

@ch1ck3n WAIT WHO UPVOTED ME

MY 1700 NOOOOOOOOOOOO

JWZ6
JWZ6

@ch1ck3n it 1705 dat also neat

ch1ck3n

@JWZ6 frick why do these people keep upvoting me

JWZ6
ch1ck3n
JWZ6

@ch1ck3n um ok...

ch1ck3n

@JWZ6


officially the smartest and best AI everrr

JWZ6

@ch1ck3n OF COURSE shoutout to @CatR3kd for making it! (sorry for the ping)

Th3Coder

@ch1ck3n

Make a good website without using StackOverFlow.

Difficulty: IMPOSSIBLE

Okay for real though...

Make an equation solver website, using DOGESCRIPT.

ch1ck3n
Th3Coder

@ch1ck3n wait you're really making it-

ch1ck3n

@Th3Coder im making the stack overflow one

JWZ6
CatR3kd

huh what did I make lmao @JWZ6

JWZ6

@CatR3kd the ai thingy

ch1ck3n

@CatR3kd the ai

JWZ6
CatR3kd

Oh yeah :3 @JWZ6

JWZ6
Th3Coder

@ch1ck3n good luck!

JWZ6

@Th3Coder yeeeet

ch1ck3n
JWZ6