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

Playing audio

To begin with, we have added 24 sound samples in .wav format in a folder named sounds in this chapter's code folder. These audio files correspond to the 24 notes on our keyboard. The audio files are named according to the note name it represents.

In order to keep the audio processing separate from the GUI code, we create a new file called audio.py (7.03). The code is defined as follows:

import simpleaudio as safrom _thread import start_new_threadimport timedef play_note(note_name): wave_obj = sa.WaveObject.from_wave_file('sounds/' + note_name + '.wav') wave_obj.play()def play_scale(scale): for note in scale:   play_note(note)   time.sleep(0.5)def play_scale_in_new_thread(scale):  start_new_thread(play_scale,(scale,))def play_chord(scale): ...

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