Pygame显示模块初始化并退出

时间:2012-05-05 22:12:43

标签: python pygame

打开pygame.display窗口,我会在其上调用pygame.display.quit()以破坏窗口。
因为我需要再次打开窗口,所以我会调用pygame.display.init()pygame.display.set_mode(),但在调用这两个函数后,没有任何反应。
谁能指出我这个问题的根源?

3 个答案:

答案 0 :(得分: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...

答案 1 :(得分:0)

应该是:

pygame.init()

所以我假设:

pygame.quit() 

工作原理相同

答案 2 :(得分:-1)

您是否尝试过调用pygame.quit()pygame.init()?我不相信有pygame.display.quit()