Code
import pygame
pygame.init()
# Set dimensions of game GUI
gameScreen = pygame.display.set_mode([600, 400])
# Take image as input
image = pygame.image.load('gfg_image.jpg')
# Set image as icon
pygame.display.set_icon(image)
# Set running value
running = True
# Setting what happens when game
# is in running state
while running:
for event in pygame.event.get():
# Closing the game if the user quits the game
if event.type == pygame.QUIT:
running = False
# Setting the background colour
gameScreen.fill((255, 255, 0))
# Drawing a circle
pygame.draw.circle(gameScreen, (0, 0, 0), (300, 200), 75)
# Update the GUI
pygame.display.update()
# Quit the GUI game
You can also try this code with Online Python Compiler
Run Code
Check out this problem - Optimal Strategy For A Game
Frequently Asked Questions
What is pygame used for?
The pygame library is an open-source module for the Python programming language that is designed to assist you in the development of games and other multimedia applications. Pygame, which is based on the SDL (Simple DirectMedia Layer) development library, can run on a variety of platforms and operating systems.
Is pygame suitable for beginners?
Pygame is a platform where you can use a set of Python modules to develop a game. It is an easy-to-understand and beginner-friendly platform that can help you develop games quickly.
Is pygame free to use?
Pygame is a Python-based free and open-source programming language library. The software can be used to create multimedia applications, including art, music, sounds, and movies.
Is Pygame easier than Tkinter?
First and foremost, Tkinter is not the best Python GUI toolkit. It's one of the most basic, and it's typically included with the Python interpreter. However, it lacks the strength of Qt, wx, or Gtk. pygame is a Python library that allows you to quickly develop games rather than GUIs, as the name implies.
Is pygame still used?
Pygame version 2 was planned as "Pygame Reloaded" in 2009, but the development and maintenance of Pygame completely stopped until the end of 2016 with version 1.9. 1. After the release of version 1.9. 5 in March 2019, the development of a new version 2 is active on the roadmap.
Conclusion
So, in a nutshell, we learnt how we can change the Icon of the game in Pygame and what's the general way to run the program.
Check out our Coding Ninjas Studio Guided Path to learn about Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and more, Take a look at the mock test series and participate in the contests hosted by Coding Ninjas Studio if you want to improve your coding skills. If you are new to preparation and want to work for firms such as Amazon, Microsoft, Uber, and others, you should review the problems, interview experiences, and interview bundle for placement preparations.
Consider taking one of our paid courses to give yourself and your profession an edge!
Please vote for our blogs if you find them valuable and exciting.
Happy Learning!!