属性错误:"builtin_function_or_method"对象没有属性"append" [英] Attribute Error: 'builtin_function_or_method' object has no attribute 'append'

查看:1077
本文介绍了属性错误:"builtin_function_or_method"对象没有属性"append"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码用于创建行走动画.我不知道是什么原因导致属性错误.

This code is to create a walking animation. I dont know what is causing an attribute error.

class player(pygame.sprite.Sprite):
    def init(self):
        pygame.sprite.Sprite.init(self)
        self.images = []
        for i in range(1, 5):
            img = pygame.image.load(os.path.join('Assets','Arts','xeonsheet','xeonsheet_' + str(i) + '.png'))
            self.images.append(img)
            self.images = self.images[0]
            self.images = self.images.get_rect

player = player()
player_list = pygame.sprite.Group()
player_list.add(player)


Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/Dreamwind-Chronicles/main.py", line 121, in <module>
    player = player()
  File "C:/Users/User/PycharmProjects/Dreamwind-Chronicles/main.py", line 117, in init
    self.images.append(img)
Attribute Error: 'builtin_function_or_method' object has no attribute 'append'

代码有什么问题?

推荐答案

目前尚不清楚您的最终意图是什么,但是通过代码进行跟踪,我可以看到您正在使用get_rect函数覆盖self.images./p>

It's not fully clear what your final intention is, but tracing through the code, I can see you are overwriting self.images with the get_rect function.

self.images.append(img)
self.images = self.images[0]
self.images = self.images.get_rect

重复此代码后,self.images现在是get_rect函数. 我猜想您只想删除最后两行,然后在渲染它们时访问图像的属性?

Once this code repeats, self.images is now the get_rect function. I'm guessing that you'll just want to remove those last two lines and then access the properties of the image at the time you render them?

这篇关于属性错误:"builtin_function_or_method"对象没有属性"append"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆