
Welcome to Lesson 1 of our Pygame Tutorial for Kids series. In this lesson, you will learn how to create your first game window using Pygame. This is the first step in Python game development, and it forms the foundation for building exciting games in Pygame.
By the end of this lesson, you’ll be able to open a game screen and understand how a basic Pygame program works. Let’s start your journey into creating fun games with Python and Pygame!
Welcome, Future Game Developer!
Have you ever played games like Minecraft, Subway Surfers, Temple Run, or Mario and wondered:
“How are these games made?”
The good news is that you can start making your own games today using Python and Pygame.
Don’t worry if you have never created a game before. This tutorial is written especially for beginners and kids.
By the end of this lesson, you will create your very first game window.
Let’s start!
What is Pygame?
Pygame is a Python library that helps us create:
- Games
- Animations
- Interactive applications
- Fun projects
Think of Pygame as a box full of game-building tools.
With Pygame, you can create:
- Racing Games
- Shooting Games
- Platform Games
- Puzzle Games
- Adventure Games
Before We Start
Make sure you have installed:
Step 1: Install Python
Visit:
https://python.org
Download and install the latest version of Python.
During installation, check:
✅ Add Python to PATH
Step 2: Install Pygame
Open Command Prompt and type:
pip install pygame
Press Enter.
If everything works correctly, you will see:
Successfully installed pygame
Awesome! You’re ready.
Create Your First Pygame Program
Create a file named:
first_game.py
Now type the following code.
Program 1: Open a Game Window
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("My First Game")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
Save the file.
Run it.
What Happens?
A window appears like this:
+--------------------------------+
| |
| |
| |
| |
| |
| |
+--------------------------------+
Congratulations!
You just created your first game window.
You are officially a beginner game developer now.
Understanding the Code
Don’t try to memorize everything.
Let’s understand one line at a time.
Line 1
import pygame
This imports the Pygame library.
Think of it as opening your game toolbox.
Line 2
pygame.init()
This starts Pygame.
Just like turning on a gaming console before playing.
Line 3
screen = pygame.display.set_mode((800, 600))
This creates the game window.
Window Size
800 = Width600 = Height
Imagine:
+--------------------+
| |
| |
| |
+--------------------+
The bigger the numbers, the bigger the window.
Line 4
pygame.display.set_caption("My First Game")
This changes the title of the window.
You can write anything.
Example:
pygame.display.set_caption("Space Adventure")
or
pygame.display.set_caption("Ninja Hero")
Game Loop
while running:
This is called the Game Loop.
Every game has a loop.
Without it, the game closes immediately.
Think:
Game Running...Game Running...Game Running...Game Running...
It keeps repeating.
Detect Closing Window
if event.type == pygame.QUIT:
This checks whether the player clicked the X button.
If yes:
running = False
The game stops.
Exit Pygame
pygame.quit()
This closes Pygame properly.
Experiment Time
Try changing the window size.
Example:
screen = pygame.display.set_mode((1000, 700))
Run again.
What changed?
Try:
screen = pygame.display.set_mode((1200, 800))
Observe carefully.
Mini Challenge 1
Create a window with:
- Width = 1000
- Height = 500
Title:
Super Kid Game
Can you do it yourself?
Mini Challenge 2
Create a window with title:
Space Explorer
Then run the program.
Did the title change?
Great job!
Common Errors and Solutions
Error:
ModuleNotFoundError: No module named pygame
Solution:
Install Pygame again.
pip install pygame
Error:
SyntaxError
Solution:
Check:
- Missing brackets
- Missing colon :
- Spelling mistakes
Quick Revision
Today you learned:
✅ What is Pygame
✅ How to install Pygame
✅ How to create a game window
✅ How to change window title
✅ What a game loop is
✅ How to close a game properly
What’s Next?
In the next lesson, we will make our game colorful by drawing:
- Squares
- Rectangles
- Circles
- Lines
And your game window will no longer be empty.
Stay tuned!
Frequently Asked Questions (FAQ)
Is Pygame good for kids?
Yes. Pygame is one of the best ways for kids to learn programming through game development.
Do I need to know Python before learning Pygame?
Basic Python helps, but beginners can start learning both together.
Can I make real games with Pygame?
Yes. Many complete 2D games can be created using Pygame.
What age is best for learning Pygame?
Kids aged 10 years and above can start learning Pygame comfortably with beginner-friendly tutorials.
Codermantra Practice Task
Create three windows:
- My First Game
- Space Adventure
- Racing Champion
Use different window sizes and titles.
When you finish, move to Lesson 2: Drawing Shapes in Pygame.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.
Shubhranshu Shekhar is a coding instructor, mentor, and founder of VSIT Delhi with 20+ years of teaching experience (since 2004). He has guided many students who are now working in multinational companies and specializes in Full Stack Development, Python, Digital Marketing, and Data Analytics.