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

Building the score maker

Let us now build the score maker. This will display whatever is played on the piano in music notation. For the sake of program modularity, we will build the program in a separate file named score_maker.py.

We start by defining a class ScoreMaker. Since we will be showing just two octaves of notes, we will define a constant NOTES listing all the notes (7.06/score_maker.py):

class ScoreMaker:NOTES = ['C1','D1', 'E1', 'F1', 'G1','A1', 'B1', 'C2','D2', 'E2', 'F2', 'G2','A2', 'B2']

The __init__ method of this class takes the container as an argument. This is the container on which this class will draw the score (7.06/score_maker.py):

def __init__(self, container): self.canvas = Canvas(container, width=500, height = 110) ...

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