turtle.end_fill() function in Python

The turtle.end_fill() function fills the shape drawn since the last call to begin_fill(). The fill color is the one set by color() or fillcolor().

Syntax: turtle.end_fill()
Parameters: None.

Let us see an example to implement the turtle.end_fill() function in Python:

Demo29.py

# turtle.end_fill() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.fillcolor("lightblue")
t.begin_fill()
t.circle(50)            # Draw a circle
t.end_fill()            # Fill the circle

window.exitonclick()

The following is the output:

turtle.end_fill() function in Python

In the above code, we followed the below steps:

  1. Import the module: import turtle loads Python’s turtle graphics library.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() creates the turtle (your pen).
  4. Set fill color: t.fillcolor(“lightblue”) sets the interior color for filling to light blue.
  5. Begin filling: t.begin_fill() starts recording the path to fill.
  6. Draw the circle: t.circle(50) draws a full circle of radius 50 (outline uses the current pen color).
  7. End filling: t.end_fill() fills the circle with light blue.
  8. 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:

turtle.begin_fill() function in Python
turtle.clear() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment