Putting the keyboard together

Now it's finally time to combine all the preceding methods to build our complete keyboard of two octaves.

We begin by defining the exact x_coordinates for all the keys from C1 to B2 in the file constants.py as follows:

WHITE_KEY_X_COORDINATES = [0,40, 80,120, 160, 200, 240,280, 320, 360, 400, 440, 480,520]BLACK_KEY_X_COORDINATES = [30,70,150,190, 230, 310, 350, 430,470, 510]

The preceding x coordinate numbers have been obtained simply by trial and error as to emulate their location on a keyboard.

Then we modify the previously defined build_keyboard_frame method as follows:

 def build_keyboard_frame(self):   self.keyboard_frame = Frame(self.root, width=WINDOW_WIDTH,  height=KEYBOARD_HEIGHT, background='LavenderBlush2') ...

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.