The Wayback Machine - https://web.archive.org/web/20240912011301/https://www.geeksforgeeks.org/how-to-change-the-name-of-a-pygame-window/
Open In App

How to Change the Name of a Pygame window?

Last Updated : 01 Oct, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 pygame window:

Syntax: pygame.display.set_caption('Title of window')

To change the icon of pygame window:

Syntax: pygame.display.set_icon(Icon_name)

Stepwise Implementation:

Step 1: First we import and initialize all imported modules. We use import pygame to import all modules and .init() function to initialize those modules.

import pygame
pygame.init() 

Step 2: Initialize a window to display. We use .set_mode() function to create a window. We pass the width and height of our window as parameters to set_mode() function.

pygame.display.set_mode((width_of_window,height_of_window))

Step 3: To change default title and icon of pygame window we use .set_caption() and .set_icon() functions. To change icon first we load icon image using pygame.image.load(“image_path”) function, and then we use .set_icon() to change default image.

pygame.display.set_caption('GeeksforGeeks')


Icon = pygame.image.load('gfglogo.png')


pygame.display.set_icon(Icon)

Step 4: Keep that window running until the user presses the exit button. We use a variable that is true unless the user presses the quit button. To keep the game running we use a while loop and check our variable if it is true or not.

running  = True

while running:  
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:  
           running = False

Complete Code:

Python3




# import pygame module
import pygame
 
# initializing imported module
pygame.init()
 
# Displaying a window of height
# 500 and width 400
pygame.display.set_mode((400, 500))
 
# Here we set name or title of our
# pygame window
pygame.display.set_caption('GeeksforGeeks')
 
# Here we load the image we want to
# use
Icon = pygame.image.load('gfglogo.png')
 
# We use set_icon to set new icon
pygame.display.set_icon(Icon)
 
# Creating a bool value which checks if
# game is running
running = True
 
# Keep game running till running is true
while running:
     
    # Check for event if user has pushed
    # any event in queue
    for event in pygame.event.get():
         
        # If event is of type quit then set
        # running bool to false
        if event.type == pygame.QUIT:
            running = False


Output:


Previous Article
Next Article

Similar Reads

Adding Collisions Using pygame.Rect.colliderect in Pygame
Prerequisite: Drawing shapes in Pygame, Introduction to pygame In this article, we are going to use pygame.Rect.colliderect for adding collision in a shape using Pygame in Python. We can easily add collisions in Pygame shapes using the colliderect( ). For this, we are going to draw two rectangles then we will check if the rectangles are colliding o
3 min read
Python | Display text to PyGame window
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit.. Command to install pygame on wind
6 min read
Python | Drawing different shapes on PyGame window
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using this toolkit. Command to install pygame : pip instal
3 min read
How to create an empty PyGame window?
Pygame window is a simple window like any other window, in which we display our game screen. It is the first task we do so that we can display our output onto something. Our main goal here is to create a window and keep it running unless the user wants to quit. To perform these tasks first we need to install pygame package and import some pre-defin
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 programming is done in pygame and it is one of the
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 programming is done in pygame and it is one of the
2 min read
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 Win
2 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 background screen of the other windows. Thus in ord
3 min read
How to change screen background color in Pygame?
Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. Functions Used: pygame.init(): This function is used to initialize all the pygame modules.pygame.display.set_mode(): This function i
1 min read
How to change the PyGame icon?
While building a video game, do you wish to set your image or company's logo as the icon for a game? If yes, then you can do it easily by using set_icon() function after declaring the image you wish to set as an icon. Read the article given below to know more in detail. Syntax: pygame_icon = pygame.image.load('#Enter the image') pygame.display.set_
2 min read
PyQtGraph – Getting Window Flags of Plot Window
In this article we will see how we can get window flags of the plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) an
3 min read
PyQtGraph – Setting Window Flag to Plot Window
In this article we will see how we can set window flag to the plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and
3 min read
Python | Print the initials of a name with last name in full
Given a name, print the initials of a name(uppercase) with last name(with first alphabet in uppercase) written in full separated by dots. Examples: Input : geeks for geeks Output : G.F.Geeks Input : mohandas karamchand gandhi Output : M.K.Gandhi A naive approach of this will be to iterate for spaces and print the next letter after every space excep
3 min read
Python IMDbPY – Getting Person name from searched name
In this article we will see how we can get the person name from the searched list of name, we use search_name method to find all the related names.search_name method returns list and each element of list work as a dictionary i.e. they can be queried by giving the key of the data, here key will be name. Syntax : names[0]['name']Here names is the lis
2 min read
GUI application to search a country name from a given state or city name using Python
In these articles, we are going to write python scripts to search a country from a given state or city name and bind it with the GUI application. We will be using the GeoPy module. GeoPy modules make it easier to locate the coordinates of addresses, cities, countries, landmarks, and Zipcode. Before starting we need to install the GeoPy module, so l
2 min read
PyQt5 – How to change background color of Main window ?
The first step in creating desktop applications with PyQt is getting a window to show up on your desktop, in this article, we will see how we can change the color of this window. In order to change the color of the main window we use setStylesheet() method. Syntax : setStyleSheet("background-color: grey;") Argument : It takes string as an argument.
2 min read
How To Change A Tkinter Window Background Color
Changing the background color of a Tkinter window is a common task for creating visually appealing GUI applications in Python. In this article, we will explore three different approaches to achieve this. Change a Tkinter Window Background ColorBelow are some of the ways by which we can change a Tkinter window background color using Python: Using th
2 min read
Change Object Display Name using __str__ function - Django Models | Python
How to Change Display Name of an Object in Django admin interface? Whenever an instance of model is created in Django, it displays the object as ModelName Object(1). This article will explore how to make changes to your Django model using def __str__(self) to change the display name in the model. Object Display Name in Django Models Consider a proj
2 min read
PyQt5 QDateEdit - Name Change Signal
In this article we will see how we can get the name change signal of the QDateEdit. Name is basically used for finding widget in the window and also for style sheet to edit the style sheet of the given name widget. This signal is emitted after the object's name has been changed. Note: This is a private signal. It can be used in signal connections b
2 min read
Python Script to change name of a file to its timestamp
A Digital Timestamp is a sequence of characters(usually a combination of digits and delimiters), identifying the time when a certain event occurred. In computer science, timestamps are generally used for marking the time of the creation of a virtual entity but are not limited to this in its use case. Digital Timestamps are implemented in various st
3 min read
How to Change the name of a key in dictionary?
Dictionaries in Python are a versatile and powerful data structure, allowing you to store key-value pairs for efficient retrieval and manipulation. Sometimes, you might need to change the name of a key in a dictionary. While dictionaries do not directly support renaming keys, there are several ways to achieve this by creating a new key-value pair a
4 min read
Change the Name of a Django Application
Changing the name of a Django app might be necessary for various reasons, such as rebranding, restructuring, or simply improving the clarity of your project’s organization. Although Django does not provide a built-in command for renaming apps, you can accomplish this task by following a series of steps. This article will guide you through the proce
3 min read
How to Change Field Name in Django REST Framework Serializer
When working with Django REST Framework (DRF), we may encounter situations where we need to change the name of a field in a serializer. This can be useful when we want to expose a model field with a different name in our API or when we need to conform to a specific API schema. In this article, we will learn about different ways to change the field
3 min read
How to create a text input box with Pygame?
In this article, we will discuss how to create a text input box using PyGame. Installation Before initializing pygame library we need to install it. This library can be installed into the system by using pip tool that is provided by Python for its library installation. Pygame can be installed by writing these lines into the terminal. We can install
3 min read
How to add moving platforms in PyGame
Prerequisite: Drawing in Pygame In this article, we will learn how we can add moving platforms to our game using PyGame in Python. Creating a Platform We can easily create any type of platform in pygame using the draw( ) method. For this, we will create react with specific width and height using the draw.rect() function. Syntax: pygame.draw.rect(su
5 min read
How to get keyboard input in PyGame ?
While using pygame module of Python, we sometimes need to use the keyboard input for various operations such as moving a character in a certain direction. To achieve this, we have to see all the events happening. Pygame keeps track of events that occur, which we can see with the events.get() function. In this article, we are going to discuss how we
3 min read
Pygame - Surface
When using Pygame, surfaces are generally used to represent the appearance of the object and its position on the screen. All the objects, text, images that we create in Pygame are created using surfaces. Creating a surface Creating surfaces in pygame is quite easy. We just have to pass the height and the width with a tuple to pygame.Surface() metho
6 min read
Python | Display images with PyGame
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit. Command to install pygame : pip in
2 min read
Introduction to pygame
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. Installing pygame: Pygame requires Python;
5 min read
PyGame Set Mouse Cursor from Bitmap
In this article, we are going to see how to set the mouse cursor from bitmap using the PyGame module in Python. What is PyGame?It is a cross-platform set of Python modules designed for writing video games.It includes computer graphics and sound libraries designed to be used with the Python programming language.It can handle time, video, music, font
5 min read
Article Tags :
Practice Tags :