14

I have used Pygame with python 2.7 before but recently I 'upgraded' to python 3.2. I downloaded and installed the newest version of Pygame which is said to work with this version of python. I have, however, had this rather frustrating error on what should be a simple block of code. The code is:

import pygame, random

title = "Hello!"
width = 640
height = 400
pygame.init()
screen = pygame.display.set_mode((width, height))
running = True
clock = pygame.time.Clock()
pygame.display.set_caption(title)

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.quit():
            running = False
        else:
            print(event.type)
    clock.tick(240)
pygame.quit()

And every single time I run it I get:

17
1
4
Traceback (most recent call last):
  File "C:/Users/David/Desktop/hjdfhksdf.py", line 15, in <module>
    for event in pygame.event.get():
pygame.error: video system not initialized

Why am I getting this error?

Codahk
  • 1,202
  • 3
  • 15
  • 25

1 Answers1

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

In the line above, you're calling pygame.quit() which is a function, while what you really want is the constant pygame.QUIT. By calling pygame.quit(), pygame is no longer initialized, which is why you get that error.

Thus, changing the line to:

if event.type == pygame.QUIT: # Note the capitalization

Will solve your problem.

It's important to note that pygame.quit() will not exit the program.

vallentin
  • 23,478
  • 6
  • 59
  • 81
Merigrim
  • 846
  • 10
  • 18