Search code examples
pythonturtle-graphicspython-turtle

How to create custom turtle shapes


I am trying to create a turtle with a png photo as its shape. I have tried using this method:

import turtle

screen = turtle.Screen()

image = ("rocketship.png")

screen.addshape(image)
turtle.shape(image)

but then it shows this:

  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\Among_us.py", line 10, in <module>
    screen.addshape(image)
  File "C:\Users\Drukker\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 1136, in register_shape
    raise TurtleGraphicsError("Bad arguments for register_shape.\n"
turtle.TurtleGraphicsError: Bad arguments for register_shape.
Use  help(register_shape)```

Does anyone know a solution?
Thanks

Solution

  • I had the same problem just two days ago and you have to convert your png to a gif. A good site for this is https://ezgif.com/apng-to-gif. If you download it and save it, you have to find it in the computer, using the code... Here is what I did:

    import os
    from turtle import *
    sc = Screen()
    sc.setup(600,600)
    image = os.path.expanduser("~\OneDrive\Desktop\AlienGameImage.gif")
    sc.addshape(image)
    t = Turtle()
    t.shape(image)
    mainloop()
    

    The reason raise TurtleGraphicsError("Bad arguments for register_shape.\n" comes up is because it does not accept a PNG image to register it as a shape.