[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] how do I maximize the window?



Hi,

here's a minimal example that works for me. Pressing 'm' toggles between
maximized and restored. It shows a dark red background with a single pixel wide
yellow border to show the new screen area.

##########################################################################

import pygame

from pygame.locals  import *
from ctypes import windll

user32      = windll.user32
ShowWindow  = user32.ShowWindow
IsZoomed    = user32.IsZoomed

SW_MAXIMIZE =   3
SW_RESTORE  =   9

def getSDLWindow():
    return pygame.display.get_wm_info()['window']

def SDL_Maximize():
    return ShowWindow(getSDLWindow(), SW_MAXIMIZE)

def SDL_Restore():
    return ShowWindow(getSDLWindow(), SW_RESTORE)

def SDL_IsMaximized():
    return IsZoomed(getSDLWindow())

def run():
    video_flags = RESIZABLE
    size = (640, 480)
    screen = pygame.display.set_mode(size, video_flags)
    while 1:
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type in (KEYUP, KEYDOWN):
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        return
                    elif event.key == K_m:
                        if SDL_IsMaximized():
                            SDL_Restore()
                        else:
                            SDL_Maximize()
            elif event.type == pygame.VIDEORESIZE:
                size = event.size
                screen = pygame.display.set_mode(size, video_flags)
            elif event.type == pygame.VIDEOEXPOSE:
                screen.fill((80, 0, 0))
                screen.fill((255, 255, 0), pygame.Rect(0, 0, size[0]-1, 1))
                screen.fill((255, 255, 0), pygame.Rect(0, size[1]-1, size[0], 1))
                screen.fill((255, 255, 0), pygame.Rect(0, 0, 1, size[1]-1))
                screen.fill((255, 255, 0), pygame.Rect(size[0]-1, 0, 1, size[1]))
                pygame.display.flip()
        pygame.time.wait(1)

def main():
    pygame.init()
    run()
    pygame.quit()

if __name__ == "__main__":
    main()

##########################################################################

If you are still having problems, what version of Pygame and SDL are you using?

Some window sizing anomalies were fixed (when they reworked the code) in the
latest version of SDL (1.2.12).

Hope that helps,

cheers,
John.