繁体   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

我的 pygame 窗口一打开就关闭,然后显示错误 pygame.error: video system not initialized。 我使用的是 Visual Studio 2019 社区版。

pygame.quit()调用 quit 方法并pygame.quit()初始化所有 pygame 模块。 您必须评估事件类型属性是否等于常量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