18 Sep 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:

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).
- 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.
- Lift the pen: t.penup() raises the pen so movements won’t draw.
- 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:
- 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