打开 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...
关于python - Pygame显示模块初始化和退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10466411/