Filling shapes: begin_fill() and end_fill()
A turtle fill colours in a shape: start the fill, draw the shape, end the fill, and the turtle paints the area inside its moves with its fill colour.
Fill a triangle
Set the colour with fillcolor(), call begin_fill(), draw the shape, then
call end_fill():
import turtle
t = turtle.Turtle()
t.fillcolor("gold")
t.begin_fill()
t.forward(100)
t.left(120)
t.forward(100)
t.left(120)
t.forward(100)
t.end_fill()
The colour appears at end_fill(). Without a fillcolor(), shapes fill
black.
Pen colour and fill colour together
color(pen, fill) sets both colours in one line. color("red") makes both
red.
import turtle
t = turtle.Turtle()
t.color("purple", "pink")
t.pensize(4)
t.begin_fill()
t.goto(100, 0)
t.goto(100, 100)
t.goto(0, 100)
t.end_fill()
print(t.color())
Only three sides were drawn, but the square still filled. end_fill() closes
the shape back to where the fill began. The left side has no purple outline.
Check the fill with filling()
filling() is True between begin_fill() and end_fill().
import turtle
t = turtle.Turtle()
t.fillcolor("light green")
t.begin_fill()
print(t.filling())
t.goto(60, 0)
t.goto(30, 50)
t.end_fill()
print(t.filling())
Note: From Python 3.14, with t.fill(): runs begin_fill() before the
indented lines under it and end_fill() after them.
See also: Turtle colours, Turtle circles.
Your turn
Add two lines at the top: set the fill colour to "light blue", then begin the
fill. Then end the fill where the second comment says.
import turtle
t = turtle.Turtle()
# add two lines: set the fill colour to "light blue", then begin the fill
t.goto(80, 0)
t.goto(80, 80)
t.goto(0, 80)
t.goto(0, 0)
print(t.filling())
# add one line: end the fill
print(t.fillcolor())
Expected output
True
light blue