这几行 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()
这是我在运行它时遇到的错误:
Traceback (most recent call last):
File "C:/Users/Grounds Keeper Willy/Desktop/Python Code/test.py", line 12, in
if i.type() == pygame.QUIT:
TypeError: 'int' object is not callable
我发现了类似的问题,但答案表明问题也在于使用函数名作为变量,这不是我正在做的。我似乎无法弄清楚这里出了什么问题。
最佳答案
它应该是:
if i.type == pygame.QUIT:
代替:
if i.type() == pygame.QUIT:
自从
type
Event
的成员类不是函数,因此您不需要/可以使用 ()
调用它.
关于python-3.x - Pygame TypeError : 'int' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11825053/