Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

176 Chapter 8


Games and animations have several things in common. First,
they’re fun! Second, they both involve drawing graphics on the
screen and changing those graphics over time to give the illusion of
motion. We’ve been able to draw graphics from the beginning of this
book, but the Turtle library is too slow to use for a lot of animation
or moving objects. In this chapter, we’re going to install and work
with a new module, Pygame, that lets us draw, animate, and even
create arcade-style games using the skills you’ve picked up so far.

Getting All GUI with Pygame


A graphical user interface (GUI, sometimes pronounced “gooey”)
includes all the buttons, icons, menus, and windows that you see
on your computer screen; it’s how you interact with a computer.
When you drag and drop a file or click an icon to open a program,
you’re enjoying a GUI. In games, when you press keys, move your
mouse, or click, the only reason you can expect anything to happen
(like running, jumping, rotating your view, and so on) is because a
programmer set up the GUI.
Like the Turtle library, Pygame is very visual, perfect for
GUIs for games, animations, and more. It’s portable to just about
every operating system, from Windows to Mac to Linux and beyond,
so the games and programs you create in Pygame can run on pretty
much any computer. Figure 8-1 shows the Pygame website, where
you’ll go to download Pygame.

Figure 8-1: Pygame is free, and so are the tutorials and sample games on
its website.
Free download pdf