I am using a for loop and a dictionary to create buttons and labels but the command assigned to the button passes the key through. Somehow the key changes to the last iterated key on all of the buttons, therefore not passing the right things to the command. How do I fix this problem?
Example code:
from Tkinter import *
root=Tk()
dic={"hello":"friend", "goodbye":"problem", "please":"fix"}
def command(thing):
print thing
row=1
for i in dic:
Label(root, text=i).grid(row=row, column=0)
Button(root, text="Edit", command=lambda: command(i)).grid(row=row, column=1)
row+=1
root.mainloop()