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

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') ...

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