我执行错误后立即关闭窗口?

问题描述

这就是我的代码:我已经在Python 3.8,3.7.6中进行了尝试。 它打开窗口并立即关闭它。 此外,它还显示一个错误

if event.type == pygame.QUIT():
TypeError: 'int' object is not callable
import pygame

#initialize the pygame
pygame.init()

#create the screen
screen = pygame.display.set_mode((800,600))


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

解决方法

pygame.QUIT是一个枚举数常量,不可调用:
(请参见pygame.event模块)

if event.type == pygame.QUIT():

if event.type == pygame.QUIT:
,

您的代码包含错误

第13行,在 如果event.type == pygame.QUIT():TypeError:“ int”对象不可调用

退出是不可调用的,它是属性,请执行以下操作:

if event.type == pygame.QUIT: