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 complete patterns

Now our program has the ability to play any sound. But we don't just need to play a single sound. We need to play a pattern. Let's define a method called play_pattern, which reads our internal data structure and plays files accordingly (see code 3.06.py):

import time    def play_pattern(self):        self.now_playing = True        while self.now_playing:            play_list = self.get_is_button_clicked_list()            num_columns = len(play_list[0])            for column_index in range(num_columns):                column_to_play = self.get_column_from_matrix(                      play_list, column_index)                for i, item in enumerate(column_to_play):                    if item:                        sound_filename = self.get_drum_file_path(i)                        self.play_sound(sound_filename)                time.sleep(self.time_to_play_each_column()) if not self.now_playing: ...

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