[英]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.