[英]Pygame display module init and quit
打開pygame.display
窗口后,我會調用pygame.display.quit()
來破壞窗口。
因為我需要再次打開窗口,我調用pygame.display.init()
和pygame.display.set_mode()
,但在調用這兩個函數后,沒有任何反應。
誰能指出我這個問題的根源?
這是帶有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...
它應該是:
pygame.init()
所以我認為:
pygame.quit()
工作原理相同
你試過調用pygame.quit()
或pygame.quit()
pygame.init()
嗎? 我不相信有一個pygame.display.quit()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.