我正在制作一个简单的 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。
最佳答案
>>> pygame.QUIT
12
所以,
>>> pygame.QUIT() >> 12()
TypeError: 'int' object is not callable
IN text, pygame.QUIT = 12
所以执行 pygame.QUIT()
相当于执行 12()
,这是一个调用,这不是您想要的。
只需将您的行更改为:
if event.type == pygame.QUIT:
关于Python pygame事件循环类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16254481/