2015-12-13 104 views
0
import pygame 
import Selection 
import Round 
import Winner 
import Fighting 
pygame.init() 


screen = pygame.display.set_mode((640, 500)) 


def main(): 
    process = 0 

    clock = pygame.time.Clock() 
    keepGoing = True 
    while keepGoing: 
     clock.tick(30) 

     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       keepGoing = False 

     if process == 0: 
      Selection.main() 
      process += 1 
     elif process == 1: 
      Fighting.main() 
      process += 1 
    pygame.quit() 

if __name__ == "__main__": 
    main() 

出現是錯誤每次我跑我的比賽,我得到pygame.error:視頻系統未初始化

for event in pygame.event.get(): 
pygame.error: video system not initialized 

它貫穿於計劃,並得到

Selection.main() 

和調用該程序運行良好,但當關閉此程序時啓動備份在

clock.tick(30) 

但隨後停止在

for event in pygame.event.get() 

,並拋出這個錯誤。

import Round 
import Winner 

還沒有做任何事,因爲那些程序還沒有寫入。

回答

1

我跑你的代碼,並縮小到基本要素,並不能重現。你確定你把pygame.quit()放在正確的縮進級別嗎?

我可以複製相同的異常,如果我這樣做(注意pygame.quit沒有縮進)。這會殺死pygame對象,並會在第一次進入運行循環時引發異常。我將執行順序標記爲1-10,這將清楚它爲什麼會拋出異常。

import pygame #1 

pygame.init() #2 
screen = pygame.display.set_mode((640, 500)) #3 

def main(): #7 

    running = True #8 
    while(running == True): #9 
     for event in pygame.event.get(): #10 pygame doesn't exist and was killed in 4. 
      if event.type == pygame.QUIT: 
       running = False 

pygame.quit() #4 

if __name__ == "__main__": #5 
    main() #6 

異常消失當我移動內部主要的pygame的初始化和屏幕對象的創建,以及在pygame.quit調用就像這樣:

import pygame 

def main(): 
    pygame.init() 
    screen = pygame.display.set_mode((640, 500)) 

    running = True 
    while(running == True): 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       running = False 

    pygame.quit() 

if __name__ == "__main__": 
    main() 

這也適用於:

import pygame 

pygame.init() 
screen = pygame.display.set_mode((640, 500)) 

def main(): 

    keepGoing = True 
    while keepGoing: 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       keepGoing = False 

pygame.quit() 

if __name__ == "__main__": 
    main() 
相關問題