the function must accept three variables, I don’t know how to pass the button click
root.bind("<Key>", position(event= , x_global=x_global, y_global=y_global))
CodePudding user response:
The basic syntax of bind is widget.bind(event,func)
In the case of a ButtonPress it is widget.bind('<Button>',func)
where func is the address/id of the function to call. Without using lambda, eg
no parameters/'variables'
def func(e): #e is the event that is passed to func by the bind function
pass
widget.bind('<Button>',func)
3 parameters
from functools import partial
def func(e,fx,fy,fz):
pass
x=1
y=2
z=3
widget.bind('<Button>',partial(func, fx=x,fy=y,fz=z))
partial
is a handy functools function that allows the passing of arguments/variables along with the func id parameter to the function that bind works with to call.