Skip to Content
Object-Oriented Python
book

Object-Oriented Python

by Irv Kalb
January 2022
Beginner to intermediate
416 pages
10h 21m
English
No Starch Press
Content preview from Object-Oriented Python

13 Timers

This chapter is about timers. A timer allows your program to count or wait for a given amount of time before moving on to perform some other action. In the world of text-based Python programs, this is easily achieved with time.sleep() by specifying a number of seconds to sleep. To pause for two and a half seconds, you could write:

import time
time.sleep(2.5)

However, in the world of pygame, and event-driven programming in general, the user should always be able to interact with the program, so pausing in this way is inappropriate. A call to time.sleep() would make the program nonreactive during the sleeping period.

Instead, the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Object-Oriented Programming - Fourth Edition

Python Object-Oriented Programming - Fourth Edition

Steven F. Lott, Dusty Phillips
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel
Robust Python

Robust Python

Patrick Viafore

Publisher Resources

ISBN: 9781098129842Errata Page