2011-07-30 13 views
13

He usado Pygame con python 2.7 antes, pero recientemente me 'actualicé' a Python 3.2. Descargué e instalé la versión más nueva de Pygame que se dice que funciona con esta versión de python. Sin embargo, tuve este error bastante frustrante sobre lo que debería ser un simple bloque de código. El código es:Error de Pygame: sistema de video no inicializado

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

Y cada vez lo ejecuto me sale:

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 

¿Por qué recibo este error?

Respuesta

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

En la línea anterior, que está llamando pygame.quit() que es una función, mientras que lo que realmente quiere es la constante pygame.QUIT. Al llamar al pygame.quit(), pygame ya no se inicializa, por lo que obtienes ese error.

Por lo tanto, el cambio de la línea a:

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

va a resolver su problema.

Es importante tener en cuenta que pygame.quit() no saldrá del programa.

Cuestiones relacionadas