Friday, September 5, 2025
HomeLanguagesHow to get the size of PyGame Window?

How to get the size of PyGame Window?

In this article, we will learn How to get the size of 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 

Step-by-step Approach:

  1. Import pygame.
  2. Initialize pygame.
  3. Form a screen by using pygame.display.set_mode() method.
  4. Get size of formed screen by using screen.get_size() method.
  5. Quit pygame.

Below are some examples based on the above approach:

Example 1:

Python3




# import package pygame
import pygame
 
# initialize pygame
pygame.init()
 
# Form screen
screen = pygame.display.set_mode()
 
# get the default size
x, y = screen.get_size()
 
# quit pygame
pygame.display.quit()
 
# view size (width x height)
print(x, y)


Output :

1536 864

Example 2:

Python3




# import package pygame
import pygame
 
# initialize pygame
pygame.init()
 
# Form screen
screen = pygame.display.set_mode((500, 500))
 
# get the size
x, y = screen.get_size()
 
# quit pygame
pygame.display.quit()
 
# view size (width x height)
print(x, y)


Output :

500 500
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7026 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS