pygame is
Simple DirectMedia Layer is
Site Swing



This is a function I use to toggle between windowed and full screen mode. It restores the content of the screen after toggling. It only works correctly on software surfaces.

import pygame
from pygame.locals import *
def toggle_fullscreen():
    screen = pygame.display.get_surface()
    tmp = screen.convert()
    caption = pygame.display.get_caption()
    cursor = pygame.mouse.get_cursor()  # Duoas 16-04-2007 
    w,h = screen.get_width(),screen.get_height()
    flags = screen.get_flags()
    bits = screen.get_bitsize()
    screen = pygame.display.set_mode((w,h),flags^FULLSCREEN,bits)
    pygame.key.set_mods(0) #HACK: work-a-round for a SDL bug??
    pygame.mouse.set_cursor( *cursor )  # Duoas 16-04-2007
    return screen
if __name__ == '__main__':
    SW,SH = 640,480
    screen = pygame.display.set_mode((SW,SH))
    pygame.display.set_caption('this is a test')
    _quit = False
    while not _quit:
        for e in pygame.event.get():
            if (e.type is KEYDOWN and e.key == K_RETURN
                    and (e.mod&(KMOD_LALT|KMOD_RALT)) != 0):
            if e.type is QUIT: _quit = True
            if e.type is KEYDOWN and e.key == K_ESCAPE: _quit = True
        screen = pygame.display.get_surface()
        import random
        rr = random.randrange

- philhassey & illume

Added two lines to preserve the cursor shape as well. -Duoas


I had to comment the "pygame.display.quit()" line for this to work for

Keith Nemitz:

This does not work perfectly under MacOSX. When returning from fullscreen mode, the window loses its title bar. And, if you select the window from the window menu in the menu bar, an invisible window pops up with a title bar, but it is non-active.


our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Nov 17, 2015

Nov 12, 2015

Nov 11, 2015

Nov 8, 2015

Oct 16, 2015

Oct 9, 2015

Sep 11, 2015

Sep 6, 2015

Aug 26, 2015

Aug 25, 2015

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)