turtle.isdown() function in Python

The turtle.isdown() function returns True if the pen is down, False if it is up. Used to check the current state of the pen.

Syntax: turtle.isdown()
Parameters: None.

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

Demo20.py

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

import turtle

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

print("Pen is down:", t.isdown())  # Check if pen is down
t.penup()
print("Pen is down:", t.isdown())  # Check again

window.exitonclick()

The following is the output:

turtle.isdown() 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 initial pen state: print(“Pen is down:”, t.isdown()) prints whether the pen is down. By default, this is True, meaning movements would draw.
  5. Lift the pen: t.penup() raises the pen so movements won’t draw.
  6. Check again: print(“Pen is down:”, t.isdown()) prints the updated state, which is now False.

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.down() or turtle.pendown() function in Python
turtle.width() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment