Pygame 显示模块的初始化和退出

3

我打开了一个pygame.display窗口,然后调用pygame.display.quit()来销毁窗口。
因为我需要重新打开窗口,所以我又调用了pygame.display.init()pygame.display.set_mode(),但是这两个函数被调用后,没有任何反应。
有人能指出这个问题的根源吗?

3个回答

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()

所以我认为:

pygame.quit() 

工作方式相同


-1
你尝试过只调用pygame.quit()或者pygame.init()吗?我不认为有一个pygame.display.quit()

这个答案是错误的。确实有一个 pygame.display.quit,而且这并没有回答 OP 的问题。 - bcdan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接