Pygame TypeError:“int”对象不可调用

MeL*_*ode 4 pygame typeerror python-3.x

这几行 python 3.2 代码使用最新的 pygame 模块来移动图像。它与这个例子有关:http : //www.pygame.org/docs/tut/MoveIt.html

这是我的代码:

import pygame
import sys 

pygame.init()
screen = pygame.display.set_mode((600,400))
bg = pygame.image.load('bg.jpg')
player = pygame.image.load('player.jpg')
pos = player.get_rect()

while True:
    for i in pygame.event.get():
       if i.type() == pygame.QUIT:
            sys.exit()
    screen.blit(bg,(0,0))
    screen.blit(player,(i,i))
    pygame.display.update()
Run Code Online (Sandbox Code Playgroud)

这是我运行时遇到的错误:

回溯(最近一次通话):
文件“C:/Users/Grounds Keeper Willy/Desktop/Python Code/test.py”,第 12 行,在
if i.type() == pygame.QUIT:
TypeError: 'int'对象不可调用

我发现了类似的问题,但答案表明问题也使用函数名作为变量,这不是我正在做的。我似乎无法弄清楚这里出了什么问题。

slo*_*oth 5

它应该是:

if i.type == pygame.QUIT:
Run Code Online (Sandbox Code Playgroud)

代替:

if i.type() == pygame.QUIT:
Run Code Online (Sandbox Code Playgroud)

由于类的type成员Event不是函数,因此您不需要/可以使用().