Pygame Error Help – pygame.error: video system not initialized

Question:

def eventLoop():
pygame.display.update()
for event in pygame.event.get():
    if event.type == QUIT:
        pygame.quit()
        sys.exit

When running my game (calling the eventLoop() function) I get this error:

File "C:UsersSlavDesktopprojecttest.py", line 342, in eventLoop
pygame.display.update()
pygame.error: video system not initialized

Pygame is initialized in this function here (before eventLoop() is defined):

def initialise(window_width, window_height, window_name, window_colour):
    pygame.init()
    screen = pygame.display.set_mode((window_width, window_height), 0, 32)
    pygame.display.set_caption(window_name)
    screen.fill(window_colour)
    return screen

The initialise function is called here :

if show_generation:
    screen = initialise(width, height, "Maze Generator", BLACK)
maze = generate_maze(show_generation, gen_choice)

if show_solving and not show_generation:
    screen = initialise(width, height, "Maze Generator", BLACK)
visited, num_items = solve_maze(sol_choice)

The show generation / show solving is a variable taken from from 2 check boxes in the app whether the user wants to just show the maze generation and / or maze solving

The eventLoop() function is called when the user has chosen to both show and solve the generated maze (right at the end of my code)

if show_generation or show_solving:
     while True:
         eventLoop()

Full Error :

x_cells: 2 
y_cells: 2 
show_generation:  True 
show_solving: True 
save_image: True
Running Kruskal�s algorithm
Running depth first search

Traceback (most recent call last):
File "C:UsersRayDesktopprojectpygame.py", line 701, in <module>
eventLoop()
File "C:UsersRayDesktopprojectpygame.py", line 342, in eventLoop
pygame.display.update()
pygame.error: video system not initialized
[Finished in 4.783s]
Asked By: slavatar__

||

Answers:

The error is in the the eventLoop()

def eventLoop():
pygame.display.update()
for event in pygame.event.get():
    if event.type == QUIT:
        pygame.quit()
        sys.exit

Instead of if if event.type == QUIT: it should be if event.type == pygame.QUIT:
Also instead of sys.exit it should be sys.exit()

So the eventLoop() should look like :

def eventLoop():
pygame.display.update()
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit() 
Answered By: CopyrightC

take away the pygame.quit() I think it fixed my problem.

Answered By: user20136095
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.