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

Determining the tempo of a rhythm

The mathematics of defining the tempo of a rhythm is simple. We get the value associated with the beats_per_minute attribute and divide it by 60 to get the beats per second. Then, the time to play each beat (or group of beats simultaneously for a given column) is the reciprocal of beats_per_second.

The code is as follows (see code 3.06.py):

def time_to_play_each_column(self):  beats_per_second = self.beats_per_minute/60  time_to_play_each_column = 1/beats_per_second  return time_to_play_each_column

While we are handling the tempo for the pattern, let's also complete coding of the command callback attached to our beats per minute Spinbox widget (see code 3.06.py):

def on_beats_per_minute_changed(self): self.beats_per_minute ...

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