Nov-11-2021, 07:27 PM
Your code does this:
To specify an argument in the command callback you can use a lambda expression or a partial function. This is your code fixed using a lambda expression.
tempValue = submitData(top) tempButton = tk.Button(top,text='Submit',command=tempValue) submitButton = tempButton.grid(row=rw,column=2,pady=5,sticky=tk.W)This ends up setting submitButton=None and probably binds the button command=None.
To specify an argument in the command callback you can use a lambda expression or a partial function. This is your code fixed using a lambda expression.
submitButton = tk.Button(top, text='Submit', command=lambda: submitData(top)) submitButton.grid(row=rw, column=2, pady=5, sticky=tk.W)The lambda expression creates a function that looks something like this:
def unnamed_function(): submitData(top)And binding command to the lambda expression does something like this:
submitButton = tk.Button(top, text='Submit', command=unnamed_function)So command is bound to a function, not a function result, and the function you want to call is not called until the lambda expression is evaluated.