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()
If we run the example above, we will see a little window, sized by the width and height variables. If we want a game to be fullscreen, we pass the pygame. FULLSCREEN flag, and there you have it, a fullscreen Pygame window.
Create a pygame window object using pygame. display. set_mode() method. It requires two parameters that define the width and height of the window.
This is a pygame. Surface. fill function which fills the Surface object, our screen, with the colour red. This basically makes everything we have drawn on the screen Surface become visible and updates the contents of the entire display.
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
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 the FULLSCREEN
tag.
In your case this would look like
DISPLAYSURF = pygame.display.set_mode((400, 300), pygame.FULLSCREEN)
(Please use the pygame.FULLSCREEN
instead of just FULLSCREEN
because upon testing with my own system FULLSCREEN
just maximized the window without fitting the resolution while pygame.FULLSCREEN
fit my resolution as well as maximizing.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With