python-3.x - Pygame TypeError : 'int' object is not callable

标签 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()

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

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/

相关文章:

Python 命名空间 'import X' 和 'from X import'

python - PyGame:将透明度应用于具有 alpha 的图像?

python - 如何在 pygame 中限制调整窗口大小

python - 类型错误:强制转换为 Unicode:需要字符串或缓冲区,找到文件(open() 函数)

python-3.x - Python pkg_resources 和包中的文件访问

python - Python 中的 Azure 服务管理 - ssl.SSLError : [SSL] PEM lib (_ssl. c:2084)

Python 3.x 导入错误 SyntaxError

使用 pygame.quit() 关闭后的 Python Pygame 在不停止整个脚本并重新启动的情况下无法再次打开它

javascript - 未捕获( promise )TypeError : Request failed

ios - 无法将类型 'SlideAnimation.Type' 的值分配给类型“UIViewControllerTransitioningDelegate”?