如何创建自定义海龟形状
How to create custom turtle shapes
我正在尝试创建一个以 png 照片为形状的乌龟。
我试过使用这个方法:
import turtle
screen = turtle.Screen()
image = ("rocketship.png")
screen.addshape(image)
turtle.shape(image)
但随后显示:
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
问题出在 .addshape()
方法上。
如果它不是 gif
文件,您必须指定 shape
属性。
在此处查看详细信息:https://docs.python.org/3/library/turtle.html#turtle.addshape
我两天前遇到了同样的问题,你必须将你的 png 转换为 gif。 https://ezgif.com/apng-to-gif 是一个不错的站点。如果你下载并保存它,你必须在电脑中找到它,使用代码......这是我所做的:
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()
出现raise TurtleGraphicsError("Bad arguments for register_shape.\n"
的原因是因为它不接受将其注册为形状的PNG图像。
我正在尝试创建一个以 png 照片为形状的乌龟。 我试过使用这个方法:
import turtle
screen = turtle.Screen()
image = ("rocketship.png")
screen.addshape(image)
turtle.shape(image)
但随后显示:
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
问题出在 .addshape()
方法上。
如果它不是 gif
文件,您必须指定 shape
属性。
在此处查看详细信息:https://docs.python.org/3/library/turtle.html#turtle.addshape
我两天前遇到了同样的问题,你必须将你的 png 转换为 gif。 https://ezgif.com/apng-to-gif 是一个不错的站点。如果你下载并保存它,你必须在电脑中找到它,使用代码......这是我所做的:
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()
出现raise TurtleGraphicsError("Bad arguments for register_shape.\n"
的原因是因为它不接受将其注册为形状的PNG图像。