0

I'm new to tkinter and I'm not 100% sure on how the whole frame, self, etc works.

I have this:

class ScalesPage(Frame):
        def GetNotes():
                key = KeyEntry.get()
                intervals = ScaleEntry.get()
                WholeNotes = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B']*4
                Root = WholeNotes.index(key)
                Chromatic = WholeNotes[Root:Root+12]
                print([Chromatic[i] for i in scales[intervals]])

        def __init__(self, parent, controller):
                Frame.__init__(self, parent)
                global KeyEntry
                KeyEntry = Entry(self)
                KeyEntry.pack()
                global ScaleEntry
                ScaleEntry = Entry(self)
                ScaleEntry.pack()
                ScaleButtonEnter = Button(self, text="Enter", command=GetNotes)
                ScaleButtonEnter.pack()

I'm trying to make the ScaleButtonEnter execute GetNotes(), but I keep getting the error

NameError: name 'GetNotes' is not defined

I'm assuming I'm missing something easy, but I'm just not familiar enough with tkinter to figure it out.

sshashank124
  • 31,495
  • 9
  • 67
  • 76

2 Answers2

0

Use self.GetNotes() instead of GetNotes().

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
Hyperplexx
  • 28
  • 1
0

You should use:

command=self.GetNotes

As using command=self.GetNotes() will just call the function there, While you need it to be called only when the button is pressed.

There is no need of using the parenthesis () and if you want to use it without any reason you will have to use lambda.

Like this:

command=lambda: self.GetNotes()

DaniyalAhmadSE
  • 807
  • 11
  • 20