Q:

Unable to get python TKInter button call work?

I am trying to call a function when a button clicked, 
When clicked it should set the value of a label.
the label initialization:
labelResult = Label(root)
labelResult.grid(row=7, column=2)

the button:
buttonCal = Button(root, command=call_result(labelResult, param1, param2)).grid(row=3, column=0)

the function:
def call_result(label_result, p1, p2):
...
...
result = ...
label_result.config(text=result)
return

When I click the button, nothing happens.
The reason is the function call_result is being executed even before I click the button.
What is going wrong here ?
am using python 3.4

A:

This can be done by using partial from the standard library functools, like this:
from functools import partial
call_result= partial(call_result, labelResult, param1, param2)
buttonCal = Button(root, command=call_result).grid(row=3, column=0) 

Or with lambda expression:
buttonCal = Button(root, command= lambda:call_result(labelResult, param1, param2)).grid(row=3, column=0) 

For each function object, the Tkinter interface layer registers a Tk command with a unique name. When that Tk command is called by the Button implementation, the command calls the corresponding Python function.

