Kewmolk
Kewmolk

Reputation: 33

How do I reference a function that is within the class as a command for a menu button?

This is the code:

class applicationUI(Frame):

    def vGuitarRender():
        print("Rendering")

    def __init__(self, master):
        Frame.__init__(self, master)
        self.master = master
        menu = Menu(master)
        master.config(menu=menu) 
        menu.add_command(label = "Virtual Guitar", command = vGuitarRender) 

Error is this:

menu.add_command(label = "Virtual Guitar", command = vGuitarRender)
NameError: name 'vGuitarRender' is not defined

It would be great to have some advice on this.

Upvotes: 2

Views: 33

Answers (1)

CDJB
CDJB

Reputation: 14516

vGuitarRender is a method within your class, so you need to use self.vGuitarRender instead.

menu.add_command(label = "Virtual Guitar", command = self.vGuitarRender) 

Upvotes: 2

Related Questions