Turtle Programming in Python (original) (raw)

Last Updated : 15 Jan, 2026

Turtle is a Python module that provides a virtual drawing board where one can control a cursor (called a turtle) to draw shapes and patterns on the screen using simple commands.

  1. **Control Movement: Move the turtle to exact positions and rotate it in any direction.
  2. **Interactive: The drawing can respond to mouse clicks or keyboard input.
  3. **Set Speed: One can make the turtle draw faster or slower to see the drawing step by step.
  4. **Change Pen Style: You can change the color and thickness of the pen and fill shapes with colors.
  5. **Draw Shapes and Stamps: You can draw shapes or leave a turtle-shaped stamp on the screen.

Plotting Using Turtle

To use Turtle in Python, simply import turtle (no installation needed). A basic Turtle program follows four steps:

**1. Import the turtle module: import Turtle in Python in the following ways.

import turtle

or

from turtle import *

2. **Create a turtle to control: After importing the turtle library, we create a drawing window and a turtle. Here, 'wn' is the window and 'skk' is the turtle.

wn = turtle.Screen()
wn.bgcolor("light green")
wn.title("Turtle")
skk = turtle.Turtle()

3. **Draw around using the turtle methods: Now that the window and turtle are ready, we can move the turtle. For example, to move skk forward by 100 pixels.

skk.forward(100)

4. **Run turtle.done(): This draws a line 100 pixels long in the direction 'skk' is facing. To finish the program, call.

turtle.done()

Examples

Below are some examples of Turtle programs demonstrating different shapes and patterns.

Shape 1: Square

In this program, we show how to draw a square using Turtle in Python.

Python `

import turtle skk = turtle.Turtle()

for i in range(4): skk.forward(50) skk.right(90)

turtle.done()

`

**Output

**Explanation:

Shape 2: Star

In this program, we show how to draw a star using Turtle in Python.

Python `

import turtle star = turtle.Turtle()

star.right(75) star.forward(100)

for i in range(4): star.right(144) star.forward(100)

turtle.done()

`

**Output

Some Turtle Programs

1. Spiral Square Outside In and Inside Out

In this program, we draw spiral squares that grow outward and inward to create a visually interesting pattern.

Python `

import turtle wn = turtle.Screen() wn.bgcolor("light green") skk = turtle.Turtle() skk.color("blue")

def sqrfunc(size): for i in range(4): skk.fd(size) skk.left(90) size = size + 5

sqrfunc(6) sqrfunc(26) sqrfunc(46) sqrfunc(66) sqrfunc(86) sqrfunc(106) sqrfunc(126) sqrfunc(146)

`

**Output

spiral

Output

**Explanation:

2. Spiral Helix Pattern

In this program, we create a spiral helix pattern by drawing circles with increasing and decreasing radii.

Python `

import turtle loadWindow = turtle.Screen() turtle.speed(2)

for i in range(100): turtle.circle(5i) turtle.circle(-5i) turtle.left(i)

turtle.exitonclick()

`

**Output

S_PIRAL

Output

**Explanation:

Common Turtle Methods

Below are some common Turtle methods used to move the turtle, draw shapes and control colors.

Method Parameter Description
Turtle() None Creates and returns a new turtle object
forward() amount Moves the turtle forward by the specified amount
backward() amount Moves the turtle backward by the specified amount
right() angle Turns the turtle clockwise
left() angle Turns the turtle counterclockwise
penup() None Picks up the turtle's Pen
pendown() None Puts down the turtle's Pen
up() None Picks up the turtle's Pen
down() None Puts down the turtle's Pen
color() Color name Changes the color of the turtle's pen
fillcolor() Color name Changes the color of the turtle will use to fill a polygon
heading() None Returns the current heading
position() None Returns the current position
goto() x, y Move the turtle to position x,y
begin_fill() None Remember the starting point for a filled polygon
end_fill() None Close the polygon and fill with the current fill color
dot() None Leave the dot at the current position
stamp() None Leaves an impression of a turtle shape at the current location
shape() shapename Should be 'arrow', 'classic', 'turtle' or 'circle'