David Green
David Green

Reputation: 1234

Python method takes exactly 1 argument (2 given)

I see where similar questions have been asked before but I don't see how to apply that to my situation. Here's the python code:

def __init__(self):
    print("running")
    #set the glade file
    self.gladefile = "/home/crokett/Data/Projects/Glade/MultiTerm.glade"
    print("Gladefile is: self.gladefile")
    #self.wTree = gtk.glade.XML(self.gladefile)
    #try gtk file
    builder = gtk.Builder()
    builder.add_from_file(self.gladefile)
    builder.connect_signals(self)

    #Get the Main Window, and connect the "destroy" event
    self.window = builder.get_object("mainWindow")
    if (self.window):
       print("Found main window")
       self.window.connect("destroy", gtk.main_quit)
       self.window.show()

def on_loadButton_clicked(self):
     self.filechooser=builder.get_object("fileChooser")
     self.filechooser.show()

With the above code, I get the error message that

TypeError: on_loadButton_clicked(self) takes exactly 1 argument (2 given)

I originally had on_LoadButton_Clicked defined as:

  on_loadButton_clicked() 

but I got the error message:

 TypeError: on_loadButton_clicked) takes exactly 0 argument (2 given)

I can post the XML if I need to. the on_loadButton_Clicked method is supposed to open a file chooser dialog

I saw posts that said I needed to define the method with (self) but I'mm not sure what the other argument would be.

Upvotes: 0

Views: 782

Answers (1)

Spice
Spice

Reputation: 352

According to very little searching, I've learned that on_loadButton_clicked should take two arguments. The first is self, and the second will be a widget. Just add a second parameter to the function, and chances are you won't actually need to use it.

Upvotes: 1

Related Questions