Allowing resizing window in PyGame
Last Updated :
24 Jan, 2021
Improve
In this article, we will learn How to allow resizing a PyGame Window.
Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the best modules for doing so.
Installation:
This library can be installed using the below command:
pip install pygame
Normal PyGame Window
Steps-by-step Approach:
- Import pygame.
- Set the title and add content.
- Run pygame.
- Quit pygame.
Below is the program based on the above approach:
# import package pygame
import pygame
# Form screen with 400x400 size
# with not resizable
screen = pygame.display.set_mode((400, 400))
# set title
pygame.display.set_caption('Not resizable')
# run window
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# quit pygame after closing window
pygame.quit()
Output :

Resizable PyGame Window
Step-by-step Approach:
- Import pygame.
- Form a screen by using pygame.display.set_mode() method and allow resizing using pygame.RESIZABLE .
- Set the title and add content.
- Run pygame.
- Quit pygame.
Below is the program based on the above approach:
# import package pygame
import pygame
# Form screen with 400x400 size
# and with resizable
screen = pygame.display.set_mode((400, 400),
pygame.RESIZABLE)
# set title
pygame.display.set_caption('Resizable')
# run window
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# quit pygame after closing window
pygame.quit()
Output :
