Skip to content
Related Articles

Related Articles

turtle.register_shape() function in Python

Improve Article
Save Article
Like Article
  • Last Updated : 28 Jul, 2020

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support.

turtle.register_shape() 

This function is used to add a turtle shape to TurtleScreen’s shapelist.

Syntax :

turtle.register_shape(name, shape=None)

Parameters:

Arguments Description 
namestring
shapetuple of pairs of coordinates

Below is the implementation of the above method with an example :

Python3




# import package
import turtle
  
# record a polygon
turtle.begin_poly()
  
# form a polygon
turtle.seth(-45)
turtle.circle(20, 90)
turtle.circle(10, 90)
turtle.circle(20, 90)
turtle.circle(10, 90)
  
turtle.end_poly()
  
# get polygon
pairs = turtle.get_poly()
  
# register shape with
# name : new_shape
# polygon : pairs
turtle.register_shape("new_shape", pairs)
  
# clear screen
turtle.clearscreen()
  
# use new shape and
# apply properties
turtle.shape("new_shape")
turtle.fillcolor("blue")
  
# do some motion
for i in range(50):
    turtle.forward(5+2*i)
    turtle.right(45)

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!