How to enlarge the display screen in PyGame?

I am new to Python programming and recently I started working with the PyGame module. Here is a simple piece of code to initialize the display screen. My question is: The maximize button is currently disabled and I cannot resize the screen. How to 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()
+4
source share
4 answers

The method you are looking for pygame.display.toggle_fullscreen

Or, as the guide recommends in most situations, calling with a tag . pygame.display.set_mode()FULLSCREEN

In your case, it will look like

DISPLAYSURF = pygame.display.set_mode((400, 300), pygame.FULLSCREEN)

(, pygame.FULLSCREEN FULLSCREEN, FULLSCREEN , pygame.FULLSCREEN , .)

+3

,

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

, pygame.RESIZABLE . , pygame.display.quit(), pygame.display.init()

pygame http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

+3

This will allow you to switch from maximizing to the original size.

import pygame, sys
from pygame.locals import *

pygame.init()

#Create a displace surface object
#Below line will let you toggle from maximize to the initial size
DISPLAYSURF = pygame.display.set_mode((400, 300), RESIZABLE)

mainLoop = True

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

pygame.quit()
+2
source

You will need to add the full screen parameter to the display declaration as follows:

import pygame, sys
from pygame.locals import *

pygame.init()

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

mainLoop = True

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

pygame.quit()
+1
source

Source: https://habr.com/ru/post/1598876/


All Articles