Lesson 11: Drawing with Turtle
Topics Covered:
- Installing and importing the
turtle
module - Creating a turtle window
- Basic turtle movement commands:
forward
,left
,right
What is Turtle Graphics?
turtle
is a Python module that lets you draw by controlling a “turtle” that moves on the screen.
Installing Turtle
If you’re using standard Python, turtle
is included by default. For online editors, check their documentation.
Basic Turtle Program
import turtle
t = turtle.Turtle()
t.forward(100) # Move forward 100 pixels
t.left(90) # Turn left 90 degrees
t.forward(100)
turtle.done() # Keep window open
Basic Commands
forward(distance)
: Move turtle forwardbackward(distance)
: Move turtle backwardleft(angle)
: Turn turtle leftright(angle)
: Turn turtle rightpenup()
andpendown()
: Lift or put down the pen
Activity: Draw a Square
import turtle
t = turtle.Turtle()
for _ in range(4):
t.forward(100)
t.left(90)
turtle.done()
Challenge
- Change the square size
- Try drawing a triangle or hexagon