显示模块初始化和退出

显示模块初始化和退出

本文介绍了Pygame 显示模块初始化和退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开一个 pygame.display 窗口,我调用 pygame.display.quit() 来销毁窗口.
因为需要再次打开窗口,所以调用了pygame.display.init()pygame.display.set_mode(),但是这两个函数调用后,什么也没有发生.
谁能指出这个问题的根源?

Having a pygame.display window open, I call pygame.display.quit() upon it in order to destroy the window.
Because I need to open the window again, I call pygame.display.init() and pygame.display.set_mode(), but after these two functions are called, nothing happens.
Can anyone point me to the root of this problem?

推荐答案

这是带有 gui 模块的示例代码...每当您调用 screen_off() 时,显示就会退出.每当您希望显示恢复时,请输入您之前使用的所有内容以将其打开.

Here is example code with a gui module... Whenever you call screen_off() then the display quits. Whenever you want display to come back, type everything you used before to turn it on.

如果需要,请使用 pygame.display.quit(),不要在 screen_off() 函数中使用它.我建议把你用来打开显示器的所有代码都放在一个函数中,这样你就不必在它被杀死后再次输入它来打开它.

If you want, use pygame.display.quit(), without it being inside the screen_off() function. I suggest taking all the code you used to get the display on, and putting it into a function so you don't have to type it again to turn it on after it's been killed.

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 显示模块初始化和退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:15