For the following piece of code, I created three entries, which initially will show [0],[1],[2],[3] respectively. If I press 'Enter' at each entry, the console should print 0,1,2,3. However, all the widgets print 3. What's the problem?
import tkinter as tk
root = tk.Tk()
def show(entryVar):
print(entryVar.get())
rootEntry = [0 for x in range(4)]
rootEntryvar = [tk.IntVar(value = x) for x in range(4)]
for i in range(4):
rootEntry[i] = tk.Entry(root, textvariable = rootEntryvar[i], width = 5)
rootEntry[i].grid(row = 0, column = i)
for i in range(4):
rootEntry[i].bind('<Return>', lambda a: show(rootEntryvar[i]))
root.mainloop()