PyGame is Python library designed for game development. PyGame is built on the top of SDL library so it provides full functionality to develop game in Python. Pygame has many modules to perform it’s operation, before these modules can be used, they must be initialized. All the modules can be initialized individually or one at a time. This post describes how all the imported modules can be initialized at a time.
Methods Used:
- pygame.init() – To initialize all the modules. It takes no arguments and return a tuble (numpass,numfail) which indicate the no of modules initialized successfully and the number of modules failed.
- pygame.get_init() – This method is used to check whether pygame modules are initialized or not.
Example 1: This example initialize all the pygame modules and print the number of modules initialized successfully.
Python3
# importing the library import pygame # initializing all the imported # pygame modules (numpass,numfail) = pygame.init() # printing the number of modules # initialized successfully print('Number of modules initialized successfully:', numpass) |
Output:
Number of modules initialized successfully: 6
Example 2: This example uses pygame.get_init() function to check whether pygame module is initialized or not.
Python3
# importing the library import pygame # initializing the modules pygame.init() # checking the initialization is_initialized = pygame.get_init() # printing the result print('Is pygame modules initialzed:', is_initialized) |
Output:
Is pygame modules initialzed: True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python Modules
- Reloading modules in Python
- Dividing a Large file into Separate Modules in C/C++, Java and Python
- Python | Opaque Pointers in C extension modules
- 10 Interesting modules in Python to play with
- Create and Import modules in Python
- How to Dynamically Load Modules or Classes in Python
- Which Python Modules are useful for competitive programming?
- Basics Of Python Modules
- Modules available for Serialization and Deserialization in Python
- Python | Display images with PyGame
- Python | Display text to PyGame window
- Python | Drawing different shapes on PyGame window
- 8-bit game using pygame
- Python | Making an object jump in PyGame
- Python | Playing audio file in Pygame
- Python - Moving an object in PyGame
- Python - Drawing design using arrow keys in PyGame
- Bubble sort visualizer using PyGame
- How to create Buttons in a game using PyGame?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

