3
votes
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:\Users\Slav\Desktop\project\test.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:\Users\Ray\Desktop\project\pygame.py", line 701, in <module>
eventLoop()
File "C:\Users\Ray\Desktop\project\pygame.py", line 342, in eventLoop
pygame.display.update()
pygame.error: video system not initialized
[Finished in 4.783s]
1
Welcome to SO. There's not much to go by with these two snippets of code. How are you actually executing those functions? And in what order? - ewong
Changed post accordingly. - slavatar__
The problem with how you're presenting your code is not in sequence. Can you please re-edit your post such that you are presenting the code as is? What is show_generation and show_solving? - ewong
Hopefully that gives you a better idea ? - slavatar__
Please show what is printed out before the error. - ewong

1 Answers

1
votes

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()