I was trying to use the GUI Buttons in Tkinter and ran into a problem when trying to use them. This code should (at least I expected it to) generate a few buttons, that, when clicked, print out the letter that is showing. However, no matter which button is pressed, it always prints out the last-generated button's result. Is there a different way I should be using functions like this?
import tkinter
win = tkinter.Tk()
players = ["A","B","C","D"]
for p in players:
playerBtn = tkinter.Button(win,text=p,command=lambda : print(p))
playerBtn.pack()
tkinter.mainloop()