python – pygame.error: video system not initialized

python – pygame.error: video system not initialized

You havent called pygame.init() anywhere.

See the basic Intro tutorial, or the specific Import and Initialize tutorial, which explains:

Before you can do much with pygame, you will need to initialize it. The most common way to do this is just make one call.

pygame.init()

This will attempt to initialize all the pygame modules for you. Not all pygame modules need to be initialized, but this will automatically initialize the ones that do. You can also easily initialize each pygame module by hand. For example to only initialize the font module you would just call.

In your particular case, its probably pygame.display thats complaining that you called either its set_caption or its flip without calling its init first. But really, as the tutorial says, its better to just init everything at the top than to try to figure out exactly what needs to be initialized when.

Changing code to this, avoids that error.
while running:
clock.tick(fps_cap)

for event in pygame.event.get(): #error is here
    if event.type == pygame.QUIT:
        running = False
        pygame.quit()
if running:
     screen.fill(white)
     pygame.display.flip()

python – pygame.error: video system not initialized

You get an error because you try to set the window title (with set_caption()) but you havent created a pygame window, so your screen variable is just a tuple containing the size of your future window.

To create a pygame window, you have to call pygame.display.set_mode(windowSize).

Good luck 🙂

Leave a Reply

Your email address will not be published.