O'Reilly logo

Adventures in Python by Craig Richardson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ch08-pag181

In this adventure, you’ll learn how to use images with Python and PyGame. During previous adventures you’ve used PyGame’s drawing functions to draw shapes. You’ve discovered how flexible this is and how much it allows you to do, but it can’t do everything! Sometimes you will want to use images from other programs instead of drawing them with code.

During this adventure, you’ll create programs to load and layer images. You’ll create a program that lets you add a moustache to any image and another program to move a sprite around the window, which forms the basis of a game.

Loading an Image

The first thing you’ll do in this adventure is learn how to load and display an image. Before you can start, you’ll need to save your chosen images into the folder that the program will be saved in. In this adventure I’ve chosen the images for you. To download these images, follow the steps given in the Appendix.

Finished? Once you have the images, copy all of them into the Adventure 8 folder.

The first images you will be using are catSmall.png, catLarge.png, hat.png and space.png. Make sure they are in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required