1
import pygame

pygame.init()

screen = pygame.display.set_mode((800,600))
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.quit():
            running = False

This code right here is basic pygame code with window size, the main game loop, and event loop.

When I run this code, the pygame window opens and closes instantly. It gives me this error:

video system has not initialized, line 11, in <module> for event in pygame.event.get():
martineau
  • 119,623
  • 25
  • 170
  • 301
Snowed
  • 13
  • 3

1 Answers1

2

Your culprit is this line:

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

Instead of checking for the QUIT event, you're calling the pygame.quit() function the first time your program enters the game loop, and the function uninitializes your pygame state, which then causes your game to crash the next time you try to access any pygame state.

What you want is to check if you got the pygame.QUIT event.

import pygame

pygame.init()

screen = pygame.display.set_mode((800,600))
running = True
while running:
    for event in pygame.event.get():
        # this should be the event pygame.QUIT
        # and not the function pygame.quit()
        if event.type == pygame.QUIT:
            running = False
wkl
  • 77,184
  • 16
  • 165
  • 176
  • Changing my code to this fixes the code stopping instantly, but now it gives me a new error called "Int object is not callable" and I cannot close the program without stopping it in the code editor. – Snowed Aug 03 '22 at 23:10