Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Visual studio pygame.error: video system not initialized

+8 votes
asked Jan 25, 2024 by Jere (200 points)

Here is my code to test pygame after installation:

import pygame

pygame.init()

screen = pygame.display.set_mode((400300))

done = False

while not done:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            done = True

pygame.quit()

Here is the error:

Traceback (most recent call last):
  File "a:\Visual studio stuff.....", line 18, in <module>
    main()
  File "a:\Visual studio stuff......", line 11, in main
    for event in pygame.event.get():
                 ^^^^^^^^^^^^^^^^^^
pygame.error: video system not initialized

Ive tried to look everywhere and nothing seems to work...

1 Answer

0 votes
answered Aug 6, 2024 by Vallabhi Vithlani (200 points)
import pygame

pygame.init()

screen = pygame.display.set_mode((400, 300))

done = False
clock = pygame.time.Clock()  # Create a clock object to control the frame rate

while not done:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            done = True

    screen.fill((255, 255, 255))  # Fill the screen with a white color
    pygame.display.flip()  # Update the display
    clock.tick(60)  # Limit the frame rate to 60 FPS

pygame.quit()  # Quit Pygame when the loop ends
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...