19 Sep turtle.begin_fill() function in Python
Call the turtle.begin_fill() function before drawing a shape to be filled. The turtle will remember the start point of the shape.
Syntax: turtle.begin_fill()
Parameters: None.
Let us see an example to implement the turtle.begin_fill() function in Python:
Demo28.py
# turtle.begin_fill() function in Python
# Code by Studyopedia
import turtle
window = turtle.Screen()
t = turtle.Turtle()
t.fillcolor("yellow")
t.begin_fill() # Start recording vertices for filling
for _ in range(4):
t.forward(100)
t.left(90)
t.end_fill() # Fill the shape
window.exitonclick()
The following is the output:

In the above code, we followed the below steps:
- Import the module: import turtle loads Python’s turtle graphics library.
- Create the screen: window = turtle.Screen() opens the drawing window.
- Create the turtle: t = turtle.Turtle() creates the turtle (your pen).
- Set fill color: t.fillcolor(“yellow”) sets the interior color used when filling shapes to yellow.
- Begin filling: t.begin_fill() starts recording the path you draw next so it can be filled.
- Draw the square:
- Loop: for _ in range(4): repeats the next two commands four times.
- Side: t.forward(100) draws one side of length 100.
- Turn: t.left(90) turns 90° to make right angles.
- End filling: t.end_fill() fills the traced square with yellow (the outline remains whatever the current pen color is).
- Close on click: window.exitonclick() keeps the window open until you click, then closes.
If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- OpenCV Tutorial
- Python Tutorial
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- Generative AI Tutorial
- LangChain Tutorial
- RAG Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments