Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

python - 'TypeError:参数1必须是pygame.Surface,而不是list':不理解(' TypeError: argument 1 must be pygame.Surface, not list ' : Not understanding)

I've seen other pages like this, but the answers were made to their code, and I am not understanding it, the error says:

(我看过其他类似的页面,但是答案是对他们的代码的,但我不理解,错误提示:)

TypeError: argument 1 must be pygame.Surface, not list

(TypeError:参数1必须是pygame.Surface,而不是list)

Here is the code:

(这是代码:)

def get_mask(self):
    return pygame.mask.from_surface(self.img)

def draw_window(win, block):
    win.blit(BG_IMG, (0, 0))
    block.draw(win)
    pygame.display.update()

def main():
    block = Block(200,200)
    win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))

    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

            draw_window(win, block)

    pygame.quit()
    quit()

main()

So if you have an answer, please tell!

(因此,如果您有答案,请告诉!)

  ask by masmohr translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably you've create a list, when you've initialized BG_IMG :

(初始化BG_IMG时,可能已经创建了一个列表:)

BG_IMG = [pygame.image.load(...)]

So the variable BG_IMG is not a single pygame.Surface instance.

(因此,变量BG_IMG不是单个pygame.Surface实例。)

It is a list with 1 element.

(这是一个包含1个元素的列表。)

Declare a single object rather than a list:

(声明一个对象而不是一个列表:)

BG_IMG = pygame.image.load(...)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...