pygame.display.update() error: video system not initialized

前端 未结 1 423
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 07:41
import pygame
from pygame.locals import*

def main():
   global FPSCLOCK, DISPLAYSURF, BASICFONT, PLAY_SURF, PLAY_RECT, NEW_SURF, NEW_RECT, SOLVE_SURF, SOLVE_RECT 


bla         


        
1条回答
  •  太阳男子
    2021-01-27 08:28

    I assume you mean this error occurs when you quit the game. pygame.quit() uninitializes all pygame modules, but the while loop still keeps running and when pygame.display.update() is called, the video system is not initialized anymore and the error is caused. To fix that problem do something like this:

    running = True
    
    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
    
        # Game code ...
    
    # After the while loop is done, uninitialize pygame and exit the program.
    pygame.quit()
    sys.exit()  # import sys at the top of the module.
    

    0 讨论(0)
提交回复
热议问题