Question

[Solved] pygame.error: video system not initialized. pygame.init() already called

This is pretty much the simplest code you can make in pygame. All it does is create a window and allow you to close it. However, I am getting this error
pygame.error: video system not initialized. I searched online for this and it seems most people forget to call pygame.init(). I am not sure why I am getting this error.

import pygame
pygame.init()
screen = pygame.display.set_mode((900,500))
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
Enquirer: Jonathan

||

Solution #1:

Just add sys.exit(0) and the end and you are done

Here is some info from official document

pygame.quit() uninitialize all pygame modules quit() -> None
Uninitialize all pygame modules that have previously been initialized.
When the Python interpreter shuts down, this method is called
regardless, so your program should not need it, except when it wants
to terminate its pygame resources and continue. It is safe to call
this function more than once: repeated calls have no effect.

Note, that pygame.quit()uninitialize all pygame modules will not exit
your program. Consider letting your program end in the same way a
normal python program will end.

here is a sample code for you.

import pygame
import sys
pygame.init()
pygame.display.set_mode((900, 500 ) )


while True :
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit(0)
Respondent: Jonathan

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy