Pygame

Python Graphics Programming Using Pygame

Pygame is a third-party module for creating 2D games with Python. Pygame is a Python extension library. Pygame includes functions for graphics programming, handling user inputs, playing sounds, etc.

Pygame functions allow the game programmer to interface with the computer using a keyboard, mouse, or joystick, called the Graphical User Interface (GUI) as opposed to entering text commands using the input() function.  As you saw in the previous chapters, the text command using the input() function is called Command Line Interface.

You have learned the principles of graphics programming using Python tkinter in the Tkinter Widget chapter and Canvas Widget chapter. Now we will explore a third-party graphics module, pygame.  Pygame is free. It is released under the LGPL license. You can create open-source, freeware, shareware, and commercial games with it.

Pygame Logo
Pygame Logo

See link below regarding Pygame LGPL license.

<a href=”https://opensource.org/licenses/lgpl-license“>

Why Learn Pygame Coding

You can use Pygame for graphics programming as well as for game creation. Since computer games are fun, game development is an exciting way for teaching programming and coding to kids.

Game development helps develop the critical logic thinking and introduces the concepts of mathematics, geometry, physics, and even artificial intelligence to the kids in a fun way. Since what you program can be seen on the screen, the visual feedback helps kids learn programming concepts rather quickly.

Python and Pygame are excellent first programming languages for introducing coding to young learners.

What will you learn in this section….

In this chapter, we will introduce the concepts of pygame gradually

  • First, we will write a program to display an image on the screen.
  • Then, we will follow it with Pygame programs that use events (keyboard press or mouse clicks) to move the images.
  • Finally, we will write some simple game creation.

What is Pygame

As mentioned above, Pygame is a third-party module for graphics programming and creating 2D games with Python. Pygame is a Python extension library. 

Pygame includes computer graphics and sound libraries designed to be used with the Python programming language. Pygame can mix audio and decode streaming music.

When you install Pygame on your computer, Pygame brings with it several modules with functions for:

  • Drawing graphics,
  • Handling user inputs (mouse motion, mouse clicks, keyboard inputs handling)
  • Playing sounds.

More information on Pygame is at this link.

<a href=”https://www.pygame.org/docs/tut/PygameIntro.html“>

How to Install Pygame on Your Computer

Before you can do graphics programming using the pygame module, you need to install pygame on your computer.  Below is a link that will help you install pygame on your computer. These instructions are for Windows 10 computers or Mac OS X.

<a href=”https://cs.hofstra.edu/docs/pages/guides/InstallingPygame.html“>

Copyright © 2019 – 2024 softwareprogramming4kids.com

All Rights Reserved

Verified by MonsterInsights