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

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

首先我想说我确实查过这个问题,但似乎遇到过类似问题的每个人都找到了对我不起作用的解决方案。我正在使用 python 3.4.3 64 位和 pygame 1.9.2a 并得到标题中所述的错误。我的代码目前看起来像这样:

import pygame

pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)
red = (200,0,0)
bright_red = (255,0,0)
green = (0,200,0)
bright_green = (0,255,0)
blue = (0,0,200)
bright_blue = (0,0,255)

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Le jeux')
clock = pygame.time.Clock()

thatonething = pygame.image.load('thatonething.png')

def thatonething(x,y):
    gameDisplay.blit(thatonething,(x,y))

x = (display_width * 0.45)
y = (display_height * 0.8)

crashed = False

while not crashed:

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

    gameDisplay.fill(white)
    thatonething(x,y)
    pygame.display.update() 
    clock.tick(30) 

pygame.quit() 
quit()

运行 它给了我这个:

Traceback (most recent call last):
  File "C:/Users/Windows 8/Desktop/Scripts/New folder/Main.py", line 39, in <module>
    thatonething(x,y)
  File "C:/Users/Windows 8/Desktop/Scripts/New folder/Main.py", line 24, in thatonething
    gameDisplay.blit(thatonething,(x,y))
TypeError: argument 1 must be pygame.Surface, not function

提前致谢,如果这听起来像是一个愚蠢的问题,我们深表歉意。

编辑:感谢 Brian,现在已经解决了这个问题。对于以后可能会看到此问题的任何人,更正后的版本如下所示:

import pygame

pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)
red = (200,0,0)
bright_red = (255,0,0)
green = (0,200,0)
bright_green = (0,255,0)
blue = (0,0,200)
bright_blue = (0,0,255)

gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Le jeux')
clock = pygame.time.Clock()

thatonething = pygame.image.load('thatonething.png')

def somefunction(x,y):
    gameDisplay.blit(thatonething,(x,y))

x = (display_width * 0.45)
y = (display_height * 0.8)

crashed = False

while not crashed:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True
        print(event) #This creates a log of the events that pygame has been handling.

    gameDisplay.fill(white)
    somefunction(x,y)
    pygame.display.update() #Updates everything "pygame.display.flip()" updates just one thing
    clock.tick(30) #This defines the refresh rate i.e. 30 in brackets gives 30 fps

pygame.quit() #Closes the game (with the next line)
quit()

主要区别在于 'thatonething' 不再是函数的名称。

你有一个函数:

def thatonething(x,y):
    gameDisplay.blit(thatonething,(x,y))

当您输入 gameDisplay.blit(thatonething,(x,y)) 时,它会将参数解释为 1:thatonething、2:(x,y)

您可能打算将其他内容作为 gameDisplay.blit 的输入,因为即使您删除逗号,也会有无限递归。

我不确定这个函数在做什么,但你可能想考虑重新设计它。