Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I maximize the display screen in PyGame?

Tags:

python

pygame

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()
like image 781
Addarsh Chandrasekar Avatar asked Jul 21 '15 12:07

Addarsh Chandrasekar


People also ask

How do I make my pygame window full screen?

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.

How would you set the display screen for pygame?

Create a pygame window object using pygame. display. set_mode() method. It requires two parameters that define the width and height of the window.

What is screen fill in pygame?

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.


2 Answers

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

like image 185
muddyfish Avatar answered Oct 12 '22 01:10

muddyfish


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.)

like image 24
Zenohm Avatar answered Oct 12 '22 01:10

Zenohm