turtle.filling() function in Python

The turtle.filling() function returns True if a fill operation is in progress (i.e., after begin_fill() and before end_fill()), otherwise returns False.

Syntax: turtle.filling()
Parameters: None.

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

Demo27.py

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

import turtle

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

print("Currently filling:", t.filling())  # Check if filling
t.begin_fill()
print("Currently filling:", t.filling())  # Check again
t.end_fill()

window.exitonclick()

The following is the output:

turtle.filling() 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. Check fill state (initial): print(“Currently filling:”, t.filling()) prints whether a fill is active. Initially this is False.
  5. Start filling: t.begin_fill() begins recording the path for a filled shape; subsequent moves will define the boundary.
  6. Check fill state (during): print(“Currently filling:”, t.filling()) now prints True because a fill is in progress.
  7. End filling: t.end_fill() closes the fill operation and fills the traced region with the current fill color (if you drew a closed shape in between).

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.pencolor() function in Python
turtle.begin_fill() function in Python
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment