2014-11-05 41 views
2

所以当我尝试运行我的pygame的代码,我得到这个错误: pygame.error:未初始化pygame.error:视频系统未初始化

视频系统我指定的翼IDE告诉我,它是在以下代码

import os 
import sys 
import math 
import pygame 
import pygame.mixer 
from pygame.locals import * 

black = 0,0,0 
white = 255,255,255 
red = 255,0,0 
green = 0,255,0 
blue = 0,0,255 

screen = screen_width, screen_height = 600, 400 

clock = pygame.time.Clock() 

pygame.display.set_caption("Physics") 

fps_cap = 120 
running = True 
while running: 
    clock.tick(fps_cap) 

    for event in pygame.event.get(): #error is here 
     if event.type == pygame.QUIT: 
      running = False 

    screen.fill(white) 

    pygame.display.flip() 

pygame.quit() 
sys.exit  
#!/usr/bin/env python 

回答

8

您还没有在任何地方拨打pygame.init()

basic Intro tutorial,或特定Import and Initialize教程,这说明:

Before you can do much with pygame, you will need to initialize it. The most common way to do this is just make one call.

pygame.init() 

This will attempt to initialize all the pygame modules for you. Not all pygame modules need to be initialized, but this will automatically initialize the ones that do. You can also easily initialize each pygame module by hand. For example to only initialize the font module you would just call.

在您的特定情况下,它可能pygame.display是在抱怨,你叫无论其set_caption或其flip不首先呼叫init。但实际上,正如教程所说,最好是只有init顶部的所有内容比试图找出什么时候需要初始化什么更好。

相关问题