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()
This will let you toggle from maximize to the initial size
The method you are looking for is
pygame.display.toggle_fullscreen
Or, as the guide recommends in most situations, calling
pygame.display.set_mode()
with theFULLSCREEN
tag.In your case this would look like
(Please use the
pygame.FULLSCREEN
instead of justFULLSCREEN
because upon testing with my own systemFULLSCREEN
just maximized the window without fitting the resolution whilepygame.FULLSCREEN
fit my resolution as well as maximizing.)These are the dimensions of your screen/monitor. You can use these or reduce them to exclude borders and title bar:
You'd have to add the full screen parameter onto the display declaration like this:
To become fullscreen at native resolution, do
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 dopygame.display.quit()
followed bypygame.display.init()
You should also check the pygame documentation here http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode