Friday, December 27, 2024
Google search engine
HomeLanguagesAllowing resizing window in PyGame

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:

  1. Import pygame.
  2. Set the title and add content.
  3. Run pygame.
  4. Quit pygame.

Below is the program based on the above approach:

Python3




# 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:

  1. Import pygame.
  2. Form a screen by using pygame.display.set_mode() method and allow resizing using pygame.RESIZABLE .
  3. Set the title and add content.
  4. Run pygame.
  5. Quit pygame.

Below is the program based on the above approach:

Python3




# 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 :

RELATED ARTICLES

Most Popular

Recent Comments