Learning goals

  • Fill a shape with color.
  • Choose a fill color and a background color.
  • Explain the difference between pencolor(), fillcolor() and color().
  • Explain when Turtle fills a shape.

How do you fill a shape?

Look at this example. It draws and fills a circle.

import turtle as otto

otto.color("black")
otto.begin_fill()
otto.circle(50)
otto.end_fill()

Animation of Turtle drawing and filling a black circle.

The fill is the color inside a shape. otto.begin_fill() marks where filling starts. otto.end_fill() completes the shape and fills it.

Can you fill other shapes?

Yes. You can fill every closed shape. A closed shape ends where it started, so it has no gap.

You already know how to draw a square with forward() and left(). Put those commands between begin_fill() and end_fill():

import turtle as otto

otto.color("green")
otto.begin_fill()
otto.forward(80)
otto.left(90)
otto.forward(80)
otto.left(90)
otto.forward(80)
otto.left(90)
otto.forward(80)
otto.left(90)
otto.end_fill()

What do you think the turtle will draw? Think first, then look at the animation.

Animation of Turtle drawing and filling a green square.

The turtle draws a green square. At end_fill(), it fills the inside green.

How do you choose a line color and a fill color?

In the examples above, otto.color() gave the line and the inside the same color. You can also choose two different colors:

import turtle as otto

otto.pencolor("blue")
otto.fillcolor("orange")
otto.begin_fill()
otto.circle(50)
otto.end_fill()

Which colors will the circle get? Think first, then look at the animation.

Animation of Turtle drawing an orange-filled circle with a blue line.

The line is blue and the inside is orange.

What is the difference between pencolor(), fillcolor() and color()?

Now you know three commands for colors. This table compares them:

Command Line color Fill color
otto.pencolor("blue") blue stays the same
otto.fillcolor("orange") stays the same orange
otto.color("green") green green

How do you change the background?

Use otto.bgcolor() to set the color behind the drawing. This example makes an orange circle on black.

import turtle as otto

otto.bgcolor("black")
otto.color("orange")
otto.begin_fill()
otto.circle(50)
otto.end_fill()

Animation of Turtle drawing an orange circle on a black background.

Try it yourself: Click the Run button. The drawing appears below the code.

Then choose your own background color and circle color. Click Run again.

import turtle as otto

otto.bgcolor("black")
otto.color("orange")
otto.begin_fill()
otto.circle(50)
otto.end_fill()

Summary

Command What it does
otto.begin_fill() Marks where filling starts.
otto.end_fill() Finishes the shape and fills its inside.
otto.pencolor(color) Sets only the line color, for example "blue".
otto.fillcolor(color) Sets only the inside color, for example "yellow".
otto.color(color) Sets the line color and the inside color.
otto.bgcolor(color) Sets the background color, for example "blue".