How can I exit Fullscreen mode in Pygame?

旧城冷巷雨未停 提交于 2019-12-09 11:31:04

问题


It may be a silly question, but It's a silly problem that I can't find a doc for it.

Pygame gives me these flags for display.set.mode():

pygame.FULLSCREEN    create a fullscreen display
pygame.DOUBLEBUF     recommended for HWSURFACE or OPENGL
pygame.HWSURFACE     hardware accelerated, only in FULLSCREEN
pygame.OPENGL        create an OpenGL renderable display
pygame.RESIZABLE     display window should be sizeable
pygame.NOFRAME       display window will have no border or controls

Ok, I can enter the Fullscreen mode.. Now here's my code:

__author__ = 'EricsonWillians'

from pygame import *
import ctypes
init()
user32 = ctypes.windll.user32
screenSize = user32.GetSystemMetrics(0)/2, user32.GetSystemMetrics(1)/2

size = (screenSize)
screen = display.set_mode(size)
display.set_caption("Game")
done = False
clock = time.Clock()

def keyPressed(inputKey):
    keysPressed = key.get_pressed()
    if keysPressed[inputKey]:
        return True
    else:
        return False

while not done:
    for e in event.get():
        if e.type == QUIT:
            done = True
        if keyPressed(K_F10):
            if screen == display.set_mode(size):
                screen = display.set_mode(size, FULLSCREEN)
            else:
                screen = display.set_mode(size, "What flag should I put here for 'windowed'?")

    screen.fill((0,0,0))
    display.flip()
    clock.tick(60)

quit()

There's no way to "toggle back" the Fullscreen mode, because there's no "WINDOWED" flag as in SDL.

And "pygame.display.toggle_fullscreen()" does not work. (At least, I could not make it work).

I've tried "-1" or "0" or "not FULLSCREEN", but none of them work (With "0" as a flag, the screen gets "weird".. I dont know what happens haha, but it's not WINDOWED).


回答1:


Just don't specify any flags

if e.type is KEYDOWN and e.key == K_w:
    pygame.display.set_mode(size)
if e.type is KEYDOWN and e.key == K_f:
    pygame.display.set_mode(size, FULLSCREEN)

Works for me.

EDIT

To toggle with a single key, use:

if (e.type is KEYDOWN and e.key == K_f):
    if screen.get_flags() & FULLSCREEN:
        pygame.display.set_mode(size)
    else:
        pygame.display.set_mode(size, FULLSCREEN)


来源:https://stackoverflow.com/questions/21980395/how-can-i-exit-fullscreen-mode-in-pygame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!