I've writen this code. I Want it to print the label's text near each button when I press the button. For example when I press second button it must print 'label 2'. But it always prints last label, 'label 20'.
from tkinter import *
from tkinter import ttk
root = Tk()
for index,i in enumerate(range(0,20)):
label = ttk.Label(root, text='line {}'.format(i+1))
label.grid(row=index, column=0)
button = ttk.Button(root, text='show info', command=lambda: print(label['text']))
button.grid(row=index, column=1)
root.mainloop()
How can I fix it?
Thanks