Allowing resizing window in PyGame
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:
Python3
# import package pygameimport pygame # Form screen with 400x400 size# with not resizablescreen = pygame.display.set_mode((400, 400)) # set titlepygame.display.set_caption('Not resizable') # run windowrunning = Truewhile running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # quit pygame after closing windowpygame.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:
Python3
# import package pygameimport pygame # Form screen with 400x400 size# and with resizablescreen = pygame.display.set_mode((400, 400), pygame.RESIZABLE) # set titlepygame.display.set_caption('Resizable') # run windowrunning = Truewhile running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # quit pygame after closing windowpygame.quit() |
Output :



