full circle magazine #65
8
HOWTO - PROGRAMMING IN PYTHON 37
You can see that this routine is
pretty self explanatory. We use a
variable (self.whichway) to
determine “which way” the labels
are displaying... from Guitar to
Piano or Piano to Guitar.
Be sure to save your work at
this point, since we are going to be
making a lot of changes from here
on.
Replace the lines defining text1
and text two with the lines shown
above.
We set self.whichway to 0 which
will be our default for the swap
procedure. Then we define four
strings instead of the two we had
last time. You might notice that
strings text3 and text4 are simple
reversals of text1 and text2.
Now we will tweak the root line
definition. Change it from...
root =
GridLayout(orientation= ' v e r t i
cal', spacing=10,
cols=1,rows=3)
to
root =
GridLayout(orientation= ' v e r t i
cal', spacing=6, cols=1,
rows=4,
row_default_height=40)
We’ve changed the spacing
from 10 to 6 and set the default
row height to 40 pixels. Change the
text for the label (next line) to
“text='Transposer Ver 0.8.0'”.
Everything else stays the same on
this line.
Now change the button
definition line from...
btn1 = Button(text = " " +
text1,size=(680,40),
size_hint=(None,None),
halign='left',
font_name='data/fonts/D r o i d S a
nsMono.ttf',
padding=(20,20))
to:
btn1 = Button(text = " "
+ self.text1,size=(780,20),
size_hint=(None, None),
halign='left',
font_name='data/fonts/D r o i d S a
nsMono.ttf',
padding=(20,2),
background_color=[0.39, 0 . 0 7 , .
92,1])
Notice that I’ve changed the
formatting of the first definition
for clarity. The big changes are the
size change from 680,40 to 780,20
and the background color for the
button. Remember, we can change
the background color for buttons,
not “standard” labels.
Next, we will define three
AnchorLayout widgets for the
three buttons that we will add in
later. I named th e m al0
(AnchorLayout0), al1 and al2. We
also add the code for the About
Popup, and define our buttons
along with the bind statements.
This is shown on the next page, top
left.
Find the “s = GridLayout” line
and change the spacing from 10 to
4. Next, add the following line
after the s.bind line (right before
the for loop):
LoadLabels(0)
This calls the LoadLabels
routine with our default “which” of
0.
Next, comment out the entire
for loop code. This starts with “for i
in range(0,19):” and ends with
“s.add_widget(btn)”. We don’t
need this since the LoadLabels
routine does this for us.
self.whichway=0
self.text1 = " C | B |A#/Bb| A |G#/Ab| G |F#/Gb| F | E |D#/Eb| D |C#/Db| C |"
self.text2 = " C | B |A#/Bb| A |G#/Ab| G |F#/Gb| F | E |D#/Eb| D |C#/Db| C | B |A#/Bb | A | G # / A b | G | F # / G b | F | E | D # / A b | D | C # / D b | C | "
self.text3 = " C |C#/Db| D |D#/Eb| E | F |F#/Gb| G |G#/Ab| A |A#/Bb| B | C |"
self.text4 = " C |C#/Db| D |D#/Eb| E | F |F#/Gb| G |G#/Ab| A |A#/Bb| B | C |C#/Db | D | D # / E b | E | F | F # / G b | G | G # / A b | A | A # / B b | B | C | C # / D b | "