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.

2

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

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()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.