user7685914
user7685914

Reputation: 83

What kind of invisible arguments passed from built in function to your function , how to findout

This is an inline code of tkinter Scaler that bind to a function

self.slidery =tk.Scale(self.valuesframe, from_=-2.000, to=2.000,
    sliderlength=10, tickinterval=1, length=self.windowwidth -self.sliderresizer
    ,variable=1,label="Y",borderwidth=2,resolution=0.01,width=10, highlightthickness=10, digits=3, troughcolor="red", orient=tk.HORIZONTAL)
self.slidery.pack()
self.slidery.bind("<ButtonRelease-1>", self.GetSave("Y", self.slidery.get()))

GetSave( ) function is binded and here is the function :

def GetSave (self,event,opt,val):
    print(opt +" : "+str(val))
    pass 

What I am receiving : TypeError: GetSave() missing 1 required positional argument: 'val'

I change to :

self.slidery.bind("<ButtonRelease-1>", self.GetSave(event,"Y", self.slidery.get()))

Also tried lambda:

self.sliderx.bind("<ButtonRelease-1>",lambda x:self.GetSave("X",self.sliderx.get()))

Still Errors.

self and event auto passed to function as I know . Then what is wrong with my code ?

Upvotes: 1

Views: 112

Answers (1)

Tom Fuller
Tom Fuller

Reputation: 5349

Try this, I've slightly changed your lambda

self.sliderx.bind("<ButtonRelease-1>",lambda event: self.GetSave(event, "X",self.sliderx.get()))

Upvotes: 2

Related Questions