Learn TURTLE-GRAPHICS with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World in Python Turtle
import turtle
screen = turtle.Screen()
screen.setup(500, 300)
t = turtle.Turtle()
t.penup()
t.goto(-100, 0)
t.write("Hello World", font=("Arial", 24, "normal"))
t.hideturtle()
turtle.done()
A Python Turtle Graphics program that writes 'Hello World' on the canvas.
2
Draw a Square
import turtle
t = turtle.Turtle()
for _ in range(4):
t.forward(100)
t.right(90)
turtle.done()
Draws a square using Turtle Graphics.
3
Draw a Triangle
import turtle
t = turtle.Turtle()
for _ in range(3):
t.forward(150)
t.left(120)
turtle.done()
Draws an equilateral triangle using Turtle Graphics.
4
Draw a Circle
import turtle
t = turtle.Turtle()
t.circle(100)
turtle.done()
Draws a circle with a radius of 100 pixels.
5
Draw a Star
import turtle
t = turtle.Turtle()
for _ in range(5):
t.forward(200)
t.right(144)
turtle.done()
Draws a 5-pointed star using Turtle Graphics.
6
Draw a Spiral
import turtle
t = turtle.Turtle()
size = 10
for i in range(50):
t.forward(size)
t.right(20)
size += 5
turtle.done()
Draws a simple spiral using Turtle Graphics.
7
Change Colors
import turtle
t = turtle.Turtle()
colors = ["red", "green", "blue", "purple"]
for color in colors:
t.color(color)
for _ in range(4):
t.forward(100)
t.right(90)
t.penup()
t.forward(150)
t.pendown()
turtle.done()
Draws multiple squares in different colors.
8
Draw Concentric Circles
import turtle
t = turtle.Turtle()
radius = 20
for _ in range(10):
t.circle(radius)
t.penup()
t.sety(t.ycor() - 10)
t.pendown()
radius += 20
turtle.done()
Draws multiple concentric circles with increasing radius.
9
Animated Moving Turtle
import turtle
t = turtle.Turtle()
screen = turtle.Screen()
x, y = 0, 0
for _ in range(100):
t.goto(x, y)
x += 5
y += 5
screen.update()
turtle.done()
Moves the turtle diagonally across the screen in an animation.
10
Random Walk
import turtle
import random
t = turtle.Turtle()
t.speed(0)
for _ in range(100):
direction = random.choice([0, 90, 180, 270])
t.setheading(direction)
t.forward(30)
turtle.done()
Makes the turtle take a random walk across the screen.