error: video system not initialized; Is there a so

2019-07-17 12:05发布

问题:

I have looked and looked. Every I find this question asked, the person is told to call pygame.init() When the asker says that they have done that, there are no more replies. I've tried everything I can think of and nothing works.

Traceback (most recent call last): File "C:\Python26\TwC\main.py", line 183, in for e in pygame.event.get(): error: video system not initialized

My imports in case there's a conflict:

#imports
import os, sys
import pygame
from pygame.locals import *

Here's where I'm calling pygame.init(), just to show that I am:

#initialize
os.environ["SDL_VIDEO_CENTERED"] = "1"
pygame.init()

#setup display
pygame.display.set_caption("TwC V%s" % version)
screen = pygame.display.set_mode((320, 240))

And lastly, here's the area of the line that raises the error:

while running:

    clock.tick(60)

    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            running = False
        if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
            running = False

EDIT: Removing the section of code causing the error just causes the same error to be caused by another section, so that means issue is with pygame.init() I'm thinking of just scrapping the whole thing and redoing it. It didn't take long to do.

回答1:

Can you run this boilerplate successfully ? Pygame, simple physics engine, how to hold points between planes?



回答2:

The very simple fix is to insure that the very last line of code in your program pygame.quit() is not indented. Errors will make it seem to be earlier lines in your code....fooled me a for about 15 minutes.



标签: python pygame