I need my buttons to return their column and row values when clicked.
I’ve tried to code but not worked.
my_button = ttk.Button(mainframe)
my_button['command'] = return_func(my_button.grid_info()['row'])
my_button.grid(column=1, sticky=(W, E))
I’m creating buttons automaticly, so col and row values are changing.
How can I fix it?
When you write
return_func(inpt.grid_info()['row']), you are executingreturn_funcwith that argument. You don’t want to do this.Instead, use
lambda: return_func(inpt.grid_info()['row'])to create a container function for your function call. That way, thelambdafunction executes your function when it is called.Another way of doing this would be like so:
I haven’t worked with
tkenough to tell if you need to pass in an argument, so that might also be a problem for you.