0

When i run my projekt i get this message:

line 26, in pressed = pygame.key.get_pressed() pygame.error: video system not initialized

I tried everything I could find in the internet. I downloaded the newest python and pip version. This is my code:

import pygame
import sys

from pygame.constants import K_DOWN, K_LEFT, K_RIGHT, K_UP

pygame.init()

screen = pygame.display.set_mode((600,600))

clock = pygame.time.Clock()

BLACK = (0,0,0)
MAGENTA = (255,0,255)
x = 300
y = 300
width = 40
height = 40
go = True

while go:
    for event in pygame.event.get():
        if event.type == pygame.quit():
            go = False

    pressed = pygame.key.get_pressed()

    if pressed[K_UP]:
        y -= 3
    if pressed[K_DOWN]:
        y += 3
    if pressed[K_RIGHT]:
        x += 3
    if pressed[K_LEFT]:
        x -= 3

    screen.fill(BLACK)
    pygame.draw.rect(screen, MAGENTA, (x,y,width,height))
    pygame.display.flip()
    clock.tick(60)

pygame.quit()
sys.exit()

Please help me :)

legorack
  • 1
  • 1

1 Answers1

0

In your current code, the first time you test if event.type == pygame.quit():, you actually execute pygame.quit()

Your test should be if event.type == pygame.QUIT.

Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50