Pygame 显示模块初始化和退出

编程入门 行业动态 更新时间:2024-10-26 10:29:45
本文介绍了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 显示模块初始化和退出

本文发布于:2023-11-06 17:30:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   模块   Pygame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!