Reputation: 148
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. i use the community version of visual studio 2019.
Upvotes: 3
Views: 215
Reputation: 210880
pygame.quit()
invokes the quit method and uninitialize all pygame modules. You have to evaluate if the event type attribute is equal the constant pygame.QUIT
(see pygame.event
):
if event.type == pygame.quit():
if event.type == pygame.QUIT:
Upvotes: 3