如何解决:TypeError:参数1必须是pygame.Surface,而不是builtin_function_or_method

时间:2018-06-05 00:15:47

标签: python pygame

import pygame

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

pygame.init()

size = (800, 625)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Game of Ur")
Token = pygame.image.load("chip.png").convert
board = pygame.image.load("board.png").convert

done = False


clock = pygame.time.Clock()

while not done:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    screen.fill(WHITE)
    screen.blit(board,[0,0])

    pygame.display.flip()

    clock.tick(60)


pygame.quit()

我收到错误

Traceback (most recent call last):
  File "C:\Users\Ed\Documents\thonk\game.py", line 43, in <module>
  screen.blit(board,[0,0])
TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

错误是一个很好的暗示。 board是一种功能或方法。期待它的分配,

board = pygame.image.load("board.png").convert

啊!这是一种方法,你需要调用它来获得董事会。与Token相同的问题。简单地修复这两行是

import pygame

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

pygame.init()

size = (800, 625)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Game of Ur")
Token = pygame.image.load("chip.png").convert()
board = pygame.image.load("board.png").convert()
done = False
clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    screen.fill(WHITE)
    screen.blit(board,[0,0])
    pygame.display.flip()
    clock.tick(60)

pygame.quit()