O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

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

Initializing pygame

The pygame module is a set of highly portable modules that runs on most operating systems. We will use the mixer module from pygame to play the sound files.

Assuming that you have installed the package, let's begin by importing pygame (see code 3.06.py):

import pygame

According to the official API documentation of the mixer module at http://www.pygame.org/docs/ref/mixer.html, we need to initialize pygame before we can play back the audio files.

We initialize pygame in a new method called init_pygame (see code 3.06.py):

def init_pygame(self): pygame.mixer.pre_init(44100, -16, 1, 512) pygame.init()

The mixer.pre_init method is a special requirement for our drum machine because the lack of it causes a lot of sound lagging. ...

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