turtle.getshapes() function in Python

The turtle.getshapes() function returns a list of names of all currently available turtle shapes. This includes both built-in and user-defined shapes.

Syntax: turtle.getshapes()
Parameters: None.

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

Demo65.py

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

import turtle

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

# Get list of available shapes
shapes = turtle.getshapes()
print("Available shapes:", shapes)

window.exitonclick()

The following is the output:

turtle.getshapes() function in Python

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 available shapes: shapes = turtle.getshapes() retrieves a list of all registered turtle shapes (e.g., "arrow", "turtle", "circle", "square", "triangle", "classic"). You can also register custom shapes using register_shape().
  • Print shapes: print("Available shapes:", shapes) displays the list of shape names in 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:

turtle.getpen() function in Python
turtle.get_shapepoly() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment