2017-03-05 34 views
0

我想在pygame上運行一些教程代碼。但是,當pygame.update我得到錯誤:,沒有別的只是錯誤:然後python退出。pygame在致電更新時出現錯誤

import pygame   
pygame.init() 
gameDisplay=pygame.display.set_caption('test') 
clock=pygame.time.Clock() 
crashed= False 

while not crashed: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
     crashed = True 
     print(event) 
    pygame.display.update() 
clock.tick(60) 

回答

0

您還沒有創建窗口/屏幕,所以沒有什麼可以更新。

把這個你的循環之前和初始化後:

screen = pygame.display.set_mode((640, 480)) # or whatnot

你也有一些縮進錯誤,但考慮到這是運行我假設這是一個錯字,而縮進代碼進入後。

此外,爲了將來的參考,如果包含實際的錯誤消息(包括堆棧跟蹤),它可以幫助人們更快地回答問題。

+0

我確實包含了錯誤信息,它是文字'錯誤:',並且回溯只顯示了---> 15 pygame.display.update(),並且在代碼之前有幾行。 –