Allowing resizing window in PyGame
Last Updated :
24 Jan, 2021
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 pygame
screen = pygame.display.set_mode(( 400 , 400 ))
pygame.display.set_caption( 'Not resizable' )
running = True
while running:
for event in pygame.event.get():
if event. type = = pygame.QUIT:
running = False
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:
Python3
import pygame
screen = pygame.display.set_mode(( 400 , 400 ),
pygame.RESIZABLE)
pygame.display.set_caption( 'Resizable' )
running = True
while running:
for event in pygame.event.get():
if event. type = = pygame.QUIT:
running = False
pygame.quit()
|
Output :
Share your thoughts in the comments
Please Login to comment...