Reputation: 119
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
Upvotes: 1
Views: 3217
Reputation: 144
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.
Upvotes: 2
Reputation: 599
The problem is with .addshape()
method.
If it's not a gif
file, you have to specify shape
attribute.
See details here: https://docs.python.org/3/library/turtle.html#turtle.addshape
Upvotes: 1