Building a game using pygame

End Goal
Starting the project
Initializing the game window
Updating the pygame window
Global constants for snake game

Starting the pygame project

Ranvir Singh · 1 mins read ·
python pygame

Let’s get the project started.

This part of the tutorial is going to be the same for any of the Python projects that you are going to start.

The first thing that you have to do is install Python to get started.

You can install Python from the official Python website if you are using Windows. Most of the Mac and Linux systems come with Python preinstalled.

You can check if Python is installed in your system just by using the command.

python --version
In this tutorial, I am going to use Python 3.8. But you can follow it with whatever version you have. Please leave your comments when things are not working for your Python version or system.

Installing virtualenv

Virtual environment is a way of differentiating different development systems.

For example, you can be making different games at a time and you don’t want to mix the installation of one system with the other.

You can create a virtualenv using the following command if you are using Python 3.

python3 -m venv venv
For starting the virtualenv, just use the command,

source venv/bin/activate

Installing pygame

pip install pygame
If you are using PyCharm you can add set your virtual environment as the interpreter using the Pycharm settings/preferences.

With everything setup, we are ready to start with the tutorial and building our first game using PyGame.

Checking installation

We can check if the installation was successful by creating a file called and adding the following code.

import pygame
Try running it using python If you see a similar response on the console then it is working fine.

pygame 2.0.0 (SDL 2.0.12, python 3.8.6)
Hello from the pygame community.

About Author

Ranvir Singh

Greetings! Ranvir is an Engineering professional with 3+ years of experience in Software development.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!