我正在做一个简单的pygame游戏。我的问题是,当我尝试检查用户是否单击退出按钮时,出现错误。这是代码:
for event in pygame.event.get():
if event.type == pygame.QUIT():
pygame.quit()
sys.exit()
这是错误:
Traceback (most recent call last):
File "C:\Users\Rafi\Python Programs\Game.py", line 20, in <module>
if event.type == pygame.QUIT():
TypeError: 'int' object is not callable
此外,这可能不是,但我在Windows 8上。
答案 0 :(得分:2)
>>> pygame.QUIT
12
所以,
>>> pygame.QUIT() >> 12()
TypeError: 'int' object is not callable
在文字中,pygame.QUIT = 12
这样做pygame.QUIT()
相当于做12()
,这是一个电话,这不是你想要的。
只需将您的行更改为:
if event.type == pygame.QUIT:
答案 1 :(得分:0)
pygame.QUIT
是一个常量(如果你想知道,则为12)。它之后不需要任何()
。这就是你的全部问题。