widget.bind('<Button-1>',callback) # binding
def callback(self,event)
#do something
I need to pass an argument to callback()
. The argument is a dictionary object.
widget.bind('<Button-1>',callback) # binding
def callback(self,event)
#do something
I need to pass an argument to callback()
. The argument is a dictionary object.
What about
I think that in most cases you don't need any argument to a callback because the callback can be an instance method which can access the instance members:
But I think the functools solution proposed by Philipp is also very nice
You can also supply arguments to a callback function of a widget, given only that this widget is defined as a part of a class definition ,, i.e. consider this tiny python 2.7 program (without the parts responsible of program's execution):
NOTE THAT the supplied arguments must be proceeded with
self.
Pass the callback function to the instance and call it from the instance method.
You can use
lambda
to define an anonymous function, such as:Note that the
arg
passed in becomes just a normal argument that you use just like all other arguments:Here's the simplest and easiest-to-read solution of them all I think: