6 Object-Oriented Pygame

In this chapter I’ll demonstrate how you can use OOP techniques effectively within the pygame framework. We’ll start off with an example of procedural code, then split that code into a single class and some main code that calls the methods of that class. After that, we’ll build two classes, SimpleButton and SimpleText, that implement basic user interface widgets: a button and a field for displaying text. I’ll also introduce the concept of a callback.

Building the Screensaver Ball with OOP Pygame

In Chapter 5, we created an old-school screensaver where a ball bounced around inside a window (Listing 5-6, if you need ...

Get Object-Oriented Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.