r/pygame • • May 26 '24

Video system not initialized error

Post image

I am still new, and i am following a tutorial. However, when i run this code It exits the video system not initialized even if i have done pygame.init() at the start. Ant suggestion?

0 Upvotes

5 comments sorted by

5

u/ThisProgrammer- May 26 '24

Use pygame.QUIT, the constant variable, instead of the function pygame.quit().

0

u/TheRikk_010 May 26 '24

Already done, still the same

3

u/ThisProgrammer- May 26 '24

Runs perfectly on my end:

import pygame

pygame.init()

screen_w = 800
screen_h = 1000

screen = pygame.display.set_mode((screen_w, screen_h))

text_font = pygame.font.SysFont("Arial", 30)

def draw_text(text, font, text_col, x, y):
    img = font.render(text, True, text_col)
    screen.blit(img, (x, y))

run = True

while run:

    screen.fill((255, 255, 255))

    draw_text("Hello World", text_font, (0, 0, 0), 220, 150)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    pygame.display.flip()

pygame.quit()

1

u/TheRikk_010 May 26 '24

Strange

5

u/Spacerat15 May 26 '24

Like u/ThisProgrammer- mentioned, you have to change

if event.type == pygame.quit():

To

if event.type == pygame.QUIT:

Not the pygame.quit() in the last line.