Course Content
Week 1: Getting Started
In week 1 the basis goal is to get started with the basics.
0/2
Week 2: Variables & Data Types
Variables are containers that computer programs use to store information pertinent to what that computer program will do. Data Types are the different types of Variables and how Python uses these variables when building logic
0/2
Week 3: Making Decisions
In both computer programs and the AI world, computer programs need a way to make decisions. Booleans and Conditionals provide a way to make this happen.
0/2
learning Python Programming and also Intro to Games

Lesson 13: Installing Pygame and Drawing Windows

Topics Covered:

  • What is Pygame?
  • Installing Pygame
  • Creating a game window
  • Drawing basic shapes: rectangles and circles

What is Pygame?

Pygame is a Python library designed for making video games. It helps you create graphics, play sounds, and handle user input.

Installing Pygame

To install Pygame, open your command prompt or terminal and type:

pip install pygame

If you are using an online editor, check if Pygame is pre-installed or supported.

Creating a Basic Game Window

import pygame
import sys

pygame.init()

# Set up the window
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("My First Pygame Window")

# Main loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill((0, 0, 0))  # Fill screen with black
    pygame.display.flip()   # Update the display

pygame.quit()
sys.exit()

Drawing Shapes

You can draw shapes using Pygame’s drawing functions:

# Draw a red rectangle
pygame.draw.rect(screen, (255, 0, 0), (50, 50, 100, 50))

# Draw a blue circle
pygame.draw.circle(screen, (0, 0, 255), (320, 240), 40)

Activity: Draw Your Shapes

Modify the example to draw different colored shapes in different positions and sizes.