Building the broad GUI structure

We start as usual by building the root window (7.01/view.py):

root = Tk()
SCREEN_WIDTH = root.winfo_screenwidth()
SCREEN_HEIGHT = root.winfo_screenheight()
SCREEN_X_CENTER = (SCREEN_WIDTH - WINDOW_WIDTH) / 2
SCREEN_Y_CENTER = (SCREEN_HEIGHT - WINDOW_HEIGHT) / 2
root.geometry('%dx%d+%d+%d' % (WINDOW_WIDTH, WINDOW_HEIGHT, SCREEN_X_CENTER, SCREEN_Y_CENTER))
root.resizable(False, False)
PianoTutor(root)
root.mainloop()

We also create a new file named constants.py( 7.01), which currently holds the height parameters for the window.

We use two root window methods,  root.winfo_screenwidth()and root_winfo_screenheight(), to obtain the screen width and height, respectively. We define two constants,  WINDOW_WIDTH and WINDOW_HEIGHT, and then place the window on the x, y center of the computer screen.

Notice the line root.resizable(False, False)This root window method takes two Boolean arguments to decide if the window is resizable in the x and y directions.  Setting both arguments to False makes our window fixed in size. 

The root window is then passed as an argument to a new class, PianoTutor, which takes care of building the internals of the program. This class is defined next.

The GUI for this program is divided into four broad rows:

The topmost row is built in a Frame named mode_selector_frame and has a combobox that lets the user select from one of three options—scales, chords, and chord progressions.

The second row is a placeholder for placing the music score sheet and is accordingly called the score_sheet_frame.

The third row requires a bit of attention. Depending on what is selected in the topmost combobox, the contents of this row change.  In our code so far, (7.01/view.py), it displays three different colored frames for the three different choices one can make using the topmost combobox. Since we will place controls on this frame, we decided to call it a controls_frame for want of a better name.

The fourth row shows the piano keyboard and the frame is named keyboard_frame, the implementation of which will be discussed in the section entitled Making the Piano Keyboard.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.61.170