21 Sep turtle.get_poly() function in Python
The turtle.get_poly() function returns the coordinates of the current shape as a tuple of coordinate pairs. Useful for duplicating or analyzing custom shapes.
Syntax: turtle.get_poly()
Parameters: None.
Let us see an example to implement the turtle.get_poly() function in Python:
Demo46.py
# turtle.get_poly() function in Python
# Code by Studyopedia
import turtle
window = turtle.Screen()
t = turtle.Turtle()
# Get the polygon that represents the current shape
poly = t.get_poly()
print("Shape polygon:", poly)
window.exitonclick()
The following is the output:

In the above code, we followed the below steps:
- Import module: import turtle loads the turtle graphics library.
- Create screen: window = turtle.Screen() opens the drawing window.
- Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
- Get shape polygon: poly = t.get_poly() retrieves the coordinate pairs that define the turtle’s current shape as a polygon. If the shape isn’t polygon-based (e.g., certain images or compound shapes), this can return None.
- Print polygon: print(“Shape polygon:”, poly) outputs the polygon data (or None) to the console.
- Close on click: window.exitonclick() waits for a mouse click, then closes the window.
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