【问题标题】:How to create custom turtle shapes如何创建自定义海龟形状
【发布时间】:2021-03-22 11:18:02
【问题描述】:

我正在尝试创建一个以 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

【问题讨论】:

    标签: python turtle-graphics python-turtle


    【解决方案1】:

    两天前我遇到了同样的问题,你必须将你的 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 图像注册为形状。

    【讨论】:

    • 谢谢!!!它奏效了,我不再头疼了!!!
    • 不客气!
    【解决方案2】:

    问题在于.addshape() 方法。

    如果不是gif文件,则必须指定shape属性。

    在此处查看详细信息:https://docs.python.org/3/library/turtle.html#turtle.addshape

    【讨论】:

    • 你能解释更多吗?
    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 2016-08-31
    • 2017-10-21
    • 1970-01-01
    • 2020-05-11
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多