How do I maximize the display screen in PyGame?

Addarsh Chandrasekar picture Addarsh Chandrasekar · Jul 21, 2015 · Viewed 36.7k times · Source

I am new to Python programming and I recently started working with the PyGame module. Here is a simple piece of code to initialize a display screen. My question is : Currently, the maximize button is disabled and I cannot resize the screen. How do I enable it to switch between full screen and back? Thanks

import pygame, sys
from pygame.locals import *

pygame.init()

#Create a displace surface object
DISPLAYSURF = pygame.display.set_mode((400, 300))

mainLoop = True

while mainLoop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            mainLoop = False
    pygame.display.update()

pygame.quit()

Answer

muddyfish picture muddyfish · Jul 21, 2015

To become fullscreen at native resolution, do

DISPLAYSURF = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

To make the window resizeable, add the pygame.RESIZABLE parameter when seting the mode. You can set the mode of the screen surface multiple times but you might have to do pygame.display.quit() followed by pygame.display.init()

You should also check the pygame documentation here http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode