2012-05-05 19 views
3

有一個pygame.display窗口打開,我呼籲它pygame.display.quit()爲了銷燬窗口。
因爲我需要再次打開窗口,我打電話pygame.display.init()pygame.display.set_mode(),但是在調用這兩個函數之後,什麼都不會發生。
任何人都可以指出這個問題的根源嗎?pygame的顯示模塊初始化和退出

回答

-1

你有沒有打過電話只是pygame.quit()pygame.init()?我不相信有一個pygame.display.quit()

+0

這個答案是錯的。有一個'pygame.display.quit',加上這個不能回答OP的問題。 – bcdan

1

以下是帶gui模塊的示例代碼...只要您撥打screen_off(),顯示屏就會退出。無論何時您想要顯示返回,請鍵入您以前使用的所有內容以將其打開。

如果需要,請使用pygame.display.quit(),而不要將它放在screen_off()函數中。我建議把你用來顯示的所有代碼都放到一個函數中,這樣你就不必再次輸入它以在它被殺後打開它。

from pygame import * 
from pygame.locals import * 
import pygame, pygame.locals 

from easygui import * 

def screen_off(): 
    pygame.display.quit() 

pygame.init() 
canvas = pygame.display.set_mode((400,400),0,32) 
red = (255,0,0) 
canvas.fill(red) 
pygame.display.update() 
screen_off() #display is now OFF... 


choice = ['Yes', 'No'] 
cc = buttonbox('Continue?', "Options", choice) 
if cc == "Yes": 
    #if you don't want to type these arguments below again to turn on the display then 
    #put them into a function and call it 
    pygame.init() 
    canvas = pygame.display.set_mode((400,400),0,32) 
    purple = (204,0,204) 
    canvas.fill(purple) 
    pygame.display.update() 
    #display is now ON... 
0

它應該是:

pygame.init() 

,所以我asssume是:

pygame.quit() 

的工作原理相同