【问题标题】:Python Turtle Custom Shape Not WorkingPython Turtle 自定义形状不起作用
【发布时间】:2018-04-23 21:04:48
【问题描述】:

我已阅读答案here,但仍然无法获得适用于 Python Turtle 的自定义形状。

我的代码在这里:

import turtle

screen = turtle.Screen()
screen.register_shape('car', 'car.gif')

t = turtle.Turtle()
t.shape('car')

我收到了AttributeError: 'str' object has no attribute '_type',但我不知道为什么。根据要求,图片是正版 .gif。

有什么想法吗?

【问题讨论】:

    标签: python-3.x turtle-graphics


    【解决方案1】:

    你几乎说对了。当注册一个多边形时,你给它一个名字,但是当注册一个 GIF 图像时,你使用图像的名字:

    import turtle
    
    screen = turtle.Screen()
    screen.register_shape('car.gif')
    
    t = turtle.Turtle()
    t.shape('car.gif')
    
    screen.mainloop()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2018-09-03
      • 2021-09-04
      • 1970-01-01
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多