0

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?

1
  • 1
    Your question is "pass parameters ...": Where is your function, you want to pass the parameter? Edit your question accordingly. Commented Dec 2, 2019 at 14:31

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.