简体   繁体   中英

Pygame display module init and quit

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?

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.

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...

It should be:

pygame.init()

so i asssume that:

pygame.quit() 

works the same

Have you tried calling just pygame.quit() or pygame.init() ? I don't believe there is a pygame.display.quit() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM