Question

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

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top