Open In App

How to make a PyGame Window?

PyGame is a free and open-source cross-platform library for game development in Python. It was officially written by Pete Shinners to replace PySDL it is suitable for the creation of client-side applications and acts as standalone executables. In this article, we are going to see how to make Pygame window in Python.

Command to install pygame on Windows-based system :  



pip install pygame

Steps to make a pygame window:

Example:






# import the pygame module
import pygame
  
# Define the background colour
# using RGB color coding.
background_colour = (234, 212, 252)
  
# Define the dimensions of
# screen object(width,height)
screen = pygame.display.set_mode((300, 300))
  
# Set the caption of the screen
pygame.display.set_caption('Geeksforgeeks')
  
# Fill the background colour to the screen
screen.fill(background_colour)
  
# Update the display using flip
pygame.display.flip()
  
# Variable to keep our game loop running
running = True
  
# game loop
while running:
    
# for loop through the event queue  
    for event in pygame.event.get():
      
        # Check for QUIT event      
        if event.type == pygame.QUIT:
            running = False

Output: 

Article Tags :