Pygame Init: Getting Started with Pygame

In this Pygame article we want to learn about Pygame Init: Getting Started with Pygame, Pygame is popular Python module that is used for game development. it is an open source module that provides easy functions for game development, graphics, sound and event handling. Pygame is cross platform and can be used on Windows, macOS and Linux.

 

 

First of all we need to install pygame library and we can use pip for that

 

 

For using Pygame, we need to initialize Pygame module. this is done by calling pygame.init() function. this function initializes all the Pygame modules and prepares them for use.

 

 

After that first thing we want to do is creating Pygame window. this is done by calling pygame.display.set_mode() function. this function takes two arguments, width and height of the window.

In the above code we have created Pygame window with a size of 640 by 480 pixels. we set the title of the window. we have also created a game loop that will run until the user closes the window. inside game loop we handle events using pygame.event.get() function. we fill background of the window with white using screen.fill() function. we have also updated the screen using pygame.display.flip() function.

 

 

Run the complete code and this will be the result

Pygame Init: Getting Started with Pygame
Pygame Init: Getting Started with Pygame

 

 

 

Learn More on Pygame

Leave a Comment