How to make a PyGame Window? Last Updated : 24 Feb, 2021 Comments Improve Suggest changes Like Article Like Report 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: Import pygame moduleCreate a pygame window object using pygame.display.set_mode() method. It requires two parameters that define the width and height of the window.Window properties can be altered such as the title of the window can be set using the set_caption() method. The background color can be changed by filling the screen object using a 3 tuple of integers ranging from 0 to 255 and representing the RGB values respectively.Display the window using the flip() method. Once this method is called, the code reaches its end and the program terminates.To keep the window visible without terminating abruptly, an infinite loop can be added to the code. However, the program will not quit even if the user wants. The user has to forcibly end the program by using CTRL+C in the command line.To display the window for as long as the user does not choose to close it, pygame.event.get() method is used. This method returns a list of events. To stop the window from displaying, one has to loop through and check whether the event has a type quit. If found, one can easily exit from the loop. Example: Python3 # 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: Comment More infoAdvertise with us Next Article How to make a PyGame Window? M manandeep1610 Follow Improve Article Tags : Python Python-PyGame Practice Tags : python Similar Reads How to Install Pygame on Windows ? In this article, we will learn how to Install PyGame module of Python on Windows. PyGame is a library of python language. It is used to develop 2-D games and is a platform where you can set python modules to develop a game. It is a user-friendly platform that helps to build games quickly and easily. 2 min read How to Change the Name of a Pygame window? PyGame window is a simple window that displays our game on the window screen. By default, pygame uses "Pygame window" as its title and pygame icon as its logo for pygame window. We can use set_caption() function to change the name and set_icon() to set icon of our window. To change the name of pygam 2 min read 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 1 min read How to make a fully transparent window with PyGame ? Fully transparent windows with PyGame have their own advantage while building many games and apps via Python. Thus in order to achieve the functionality of the transparent window that allows the user to see behind a running screen. For example: Geek want to design an app, in which they can see the 3 min read PySide2 â How to create window? PySide2 is one of the most famous libraries in python for building GUI applications. In this article, we will build an empty window using PySide2 Library. Steps to create empty window : 1. Import PySide2 in your code 2. Create QApplication object 3. Create object for QWidget 4. Increase the size of 1 min read PYGLET â Show / Hide Window In this article, we will see how we can show/hide the window in PYGLET module in python. Pyglet is easy to use but a powerful library for developing visually rich GUI applications like games, multimedia, etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear 2 min read PYGLET â Maximize the Window In this article we will see how we can maximize the window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as f 2 min read 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 2 min read How to make Flappy Bird Game in Pygame? In this article, we are going to see how to make a flappy bird game in Pygame. We all are familiar with this game. In this game, the main objective of the player is to gain the maximum points by defending the bird from hurdles. Here, we will build our own Flappy Bird game using Python. We will be us 11 min read How to move an image with the mouse in PyGame? Pygame is a Python library that is used to create cross-platform video games. The games created by Pygame can be easily run through any of the input devices such as a mouse, keyboard, and joystick. Do you want to make a game that runs through mouse controls? Don't you know how to move the image with 4 min read Like