Reputation: 24
I have a key pad in tkinter made of buttons, when clicked they add their number to a string "Amount Entered" which will be converted to a float at the end.
AmountEntered = ""
Number = tk.Button(self, text = "7", command = lambda AmountEntered: AmountEntered + "7")
Number.grid(row = 0, column = 0, sticky='nsew')
however when clicked, I get the error TypeError: () missing 1 required positional argument: 'AmountEntered'
I thought that the first AmountEntered would be the parameter, what does this refer to?
Upvotes: 0
Views: 100
Reputation: 531205
The problem isn't with the lambda expression; the problem in the assumption that the callback function will be called with an argument. It won't be. AmountEntered
really is a global variable, so all you need is
Number = tk.Button(self, text="7", command=lambda: AmountEntered + "7")
Upvotes: 1