简体   繁体   English

pygame 窗口打开后立即关闭

[英]pygame window closes immediatly after opening up

import pygame
#initialize the screen
pygame.init()

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

#tile and icon
pygame.display.set_caption("Space Invaders")
icon = pygame.image.load("spaceship.png")
pygame.display.set_icon(icon)

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

my pygame window closes as soon as it opens and then it displays the error pygame.error: video system not initialized.我的 pygame 窗口一打开就关闭,然后显示错误 pygame.error: video system not initialized。 i use the community version of visual studio 2019.我使用的是 Visual Studio 2019 社区版。

pygame.quit() invokes the quit method and uninitialize all pygame modules. pygame.quit()调用 quit 方法并pygame.quit()初始化所有 pygame 模块。 You have to evaluate if the event type attribute is equal the constant pygame.QUIT (see pygame.event ):您必须评估事件类型属性是否等于常量pygame.QUIT (请参阅pygame.event ):

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

if event.type == pygame.QUIT:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM