I'm trying to call same function with different argument with correspond to for in and buttons in Tkinter python, and when I click the other buttons the value given by the function is the last calls value . I'm a js dev where have used foreach and array with similar thing.
apps=["k","c","d"]
for app in apps:
btn = tk.Button(innerFrame, text=" {}".format(app), command=(
lambda: runThis(app)))
btn.pack()
def runThis(val, i):
print("Value of the btn {}".format(val))
the expected output when I click each button is
Value of the btn k
Value of the btn c
Value of the btn d
but what I get is
Value of the btn d
Value of the btn d
Value of the btn d