I have a loop that creates a button under a label that contains a list value:
def feed_page():
feed = ["Cooking", "Sports", "Tv", "Fashion"] #let's say those are the list's values
l = len(feed) - 1
x = 0
while l >=0:
Label(app, text=feed[l]).grid(row=x, column=1)
b = Button(app, text=feed[l])
b.configure(command=lambda: print_button_pressed_text(b.cget('text')))
b.grid(row=x+1, column=1)
x += 2
*The list Feed length and values change every time the function feed_page() is called.
I want that every time a certain button is pressed, the print_button_pressed_text function will print out the text of that specific button that was pressed. (each button has his own unique number)
def print_button_pressed_text(num):
print num
However, no matter what button I press, the function prints the Value 'Fashion' (the last value in the list..)
Do you have any idea what the problem is? and how can I fix it?