Editor

Draw a House in Python Turtle

Beginner · Things to draw · 119 lines · draws in about 15 seconds

One rectangle function draws the sky, grass, walls, door, windows and chimney, and the order of the calls decides what sits in front.

Draw a House in Python Turtle: the finished drawing
import turtle
screen = turtle.Screen()
screen.bgcolor("white")
screen.title("House with a garden")
t = turtle.Turtle()
t.speed(8)
def rectangle(x, y, width, height, color):
# A filled rectangle with its bottom left corner at (x, y)
t.penup()
t.goto(x, y)
t.setheading(0)
t.pendown()
t.color(color)
t.begin_fill()
for _ in range(2):
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.end_fill()
def flower(x, y, color):
# A green stem with a coloured flower on top
t.penup()
t.goto(x, y)
t.pendown()
t.pensize(3)
t.pencolor("forestgreen")
t.goto(x, y + 30)
t.dot(22, color)
t.dot(8, "gold")
t.pensize(1)
# Sky and grass
rectangle(-300, -100, 600, 320, "skyblue")
rectangle(-300, -220, 600, 120, "mediumseagreen")
# The sun
t.penup()
t.goto(-230, 160)
t.dot(70, "gold")
# A tree: a trunk and three green dots for leaves
rectangle(198, -125, 24, 90, "saddlebrown")
t.penup()
t.goto(210, -10)
t.dot(110, "forestgreen")
t.goto(178, -40)
t.dot(70, "forestgreen")
t.goto(242, -40)
t.dot(70, "forestgreen")
# The chimney goes first, so the roof covers its bottom
rectangle(60, 50, 35, 80, "sienna")
# The walls and the roof
rectangle(-130, -150, 260, 180, "wheat")
t.penup()
t.goto(-160, 30)
t.pendown()
t.color("firebrick")
t.begin_fill()
t.goto(160, 30)
t.goto(0, 140)
t.goto(-160, 30)
t.end_fill()
# The door with a round handle
rectangle(-28, -150, 56, 100, "saddlebrown")
t.penup()
t.goto(15, -100)
t.dot(10, "gold")
# Two windows, each with a white cross in the middle
for x in [-105, 45]:
rectangle(x, -75, 60, 55, "lightblue")
t.pensize(4)
t.pencolor("white")
t.penup()
t.goto(x + 30, -75)
t.pendown()
t.goto(x + 30, -20)
t.penup()
t.goto(x, -47)
t.pendown()
t.goto(x + 60, -47)
t.pensize(1)
# A path from the door to the bottom of the picture
t.penup()
t.goto(-28, -150)
t.pendown()
t.color("tan")
t.begin_fill()
t.goto(28, -150)
t.goto(60, -220)
t.goto(-60, -220)
t.goto(-28, -150)
t.end_fill()
# Bushes by the walls and flowers along the front
t.penup()
t.goto(-135, -140)
t.dot(50, "seagreen")
t.goto(135, -140)
t.dot(50, "seagreen")
colors = ["red", "hotpink", "orange", "mediumorchid"]
for i in range(4):
flower(-270 + i * 35, -200, colors[i])
flower(165 + i * 35, -200, colors[i])
t.hideturtle()
turtle.done()

How the code works

One function, many rectangles

rectangle() goes to the bottom left corner, then does forward, left turn, forward, left turn twice. Every rectangle in the picture, from the sky to the door, is one call to it.

def rectangle(x, y, width, height, color):
    # A filled rectangle with its bottom left corner at (x, y)
    t.penup()
    t.goto(x, y)
    t.setheading(0)
    t.pendown()
    t.color(color)
    t.begin_fill()
    for _ in range(2):
        t.forward(width)
        t.left(90)
        t.forward(height)
        t.left(90)
    t.end_fill()

Chimney before roof

Later drawings cover earlier ones. The chimney goes first and reaches above the roof, so the roof hides its bottom and it looks like it comes out of the tiles. The roof is a triangle made with three goto() calls.

# The chimney goes first, so the roof covers its bottom
rectangle(60, 50, 35, 80, "sienna")

# The walls and the roof
rectangle(-130, -150, 260, 180, "wheat")
t.penup()
t.goto(-160, 30)
t.pendown()
t.color("firebrick")
t.begin_fill()
t.goto(160, 30)
t.goto(0, 140)
t.goto(-160, 30)
t.end_fill()

Windows with crosses

The loop runs once with x set to -105 and once with 45. Each time it draws a light blue rectangle and two white lines across its middle.

# Two windows, each with a white cross in the middle
for x in [-105, 45]:
    rectangle(x, -75, 60, 55, "lightblue")
    t.pensize(4)
    t.pencolor("white")
    t.penup()
    t.goto(x + 30, -75)
    t.pendown()
    t.goto(x + 30, -20)
    t.penup()
    t.goto(x, -47)
    t.pendown()
    t.goto(x + 60, -47)
    t.pensize(1)

The garden

flower() draws a green stem with two dots on top. The loop puts four flowers on each side of the path, 35 apart, and colors[i] gives each one a different colour.

# Bushes by the walls and flowers along the front
t.penup()
t.goto(-135, -140)
t.dot(50, "seagreen")
t.goto(135, -140)
t.dot(50, "seagreen")
colors = ["red", "hotpink", "orange", "mediumorchid"]
for i in range(4):
    flower(-270 + i * 35, -200, colors[i])
    flower(165 + i * 35, -200, colors[i])

Make it yours

Change the code above and press Run. Some ideas:

  • Change "firebrick" to "slategray" for a grey roof.
  • Add rectangle(-20, -40, 40, 30, "lightblue") after the windows for a small window above the door.
  • Move the sun to the other side with t.goto(230, 160) in place of t.goto(-230, 160).

What it uses

Every turtle command the site supports is listed on Python turtle online.