【问题标题】:Whenever I start my pygame game, i get this error每当我开始我的 pygame 游戏时,我都会收到此错误
【发布时间】:2015-07-20 00:48:31
【问题描述】:

我一直在关注关于如何在 pygame 中制作游戏的 youtube 系列,我不断收到有关 QUIT 事件的错误,我不知道如何解决它。

这是错误:

Traceback (most recent call last):
  File "C:/Users/Brady/Desktop/Python Programs/Climber.py", line 31, in <module>
    if event.type == pygame.QUIT():
TypeError: 'int' object is not callable

代码如下:

#Imports

import pygame
import sys
import random
import cx_Freeze

#Variables

playerhealth = 100

black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
green = (0 ,255, 0)

#Functions



#Initialization

pygame.init()
gamedisplay = pygame.display.set_mode((800, 800))
pygame.display.set_caption("Climber")

#Game Loop

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT():
            pygame.quit()
            quit()

    gamedisplay.fill(white)
    pygame.display.update()

请帮助我解决此错误以及代码中的任何其他错误。

【问题讨论】:

  • Climber.py 第 31 行有什么内容?
  • @jm_____ if event.type == pygame.QUIT():

标签: python events int pygame callable


【解决方案1】:

使用pygame.QUIT。它是一个整数常量而不是一个函数。

例如

if event.type == pygame.QUIT:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-08
    • 2021-08-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多