daFireman
daFireman

Reputation: 167

tkInter function takes exactly 1 argument 2 given

This seems to be a common issue, however I have one function which seems to work, and another which does not. I get

TypeError:clicked() takes exactly one argument, two given

Where I have binded the clicked function to a Mouse Click.

However, the handler function, which is bound with protocal to the WM_DELETE_WINDOW event, seems to work fine. How are the two different? Thanks!

class GUI():
def __init__(self,root,fit_tuples):
    self.fit_tuples=fit_tuples
    self.root=root
    self.root.title("Beam Flux Registry")
    self.root.protocol("WM_DELETE_WINDOW",self.handler)
    ...
    # Calendar Frame
    cal=Calendar(LeftFrame)
    cal.pack(side=TOP)
    cal.bind("<Button-1>",self.clicked)
    ...
    #Mainloop
    root.mainloop()

def clicked(self):
    print "%i/%i/%i"%(self.cal.selection.month,self.cal.selection.day,self.cal.selection.year)

def handler(self):
    self.root.destroy()
    self.root.quit()

Upvotes: 0

Views: 1465

Answers (1)

atlasologist
atlasologist

Reputation: 3964

You need to account for the Event object in the clicked() method. When you bind a widget, the function that handles the binding will receive an object with attributes about the event that fired the function (ie, for a mouse-click event, you'll receive an object with attributes for the cursor's x and y).

The other method works because protocol isn't passing any arguments to the handler.

Upvotes: 1

Related Questions