Pygame TypeError:'int'对象不可调用

时间:2012-08-06 08:46:43

标签: python-3.x pygame typeerror

这几行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()

以下是运行时出现的错误:

  

追踪(最近的呼叫最后):
   文件" C:/ Users / Grounds Keeper Willy / Desktop / Python Code / test.py",第12行,中
     if i.type()== pygame.QUIT:
  TypeError:' int'对象不可调用

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

1 个答案:

答案 0 :(得分:3)

应该是:

if i.type == pygame.QUIT:

而不是:

if i.type() == pygame.QUIT:

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

相关问题