How to refer to a button in the command of a button?

Viewed 19

I want to click the button and get the number of it but in this case I get 10 since after associating the command bip(x) the value of x is changing.

How can I get the data associated with the button when I click on it?

from tkinter import *
from tkinter.ttk import *

def bip(x):
    print(x)


window = Tk()
x=0
liste = []
while x < 10:
    btn = Button(text=x, command=lambda: bip(x))
    liste.append(btn)
    btn.pack()
    x = x + 1
window.mainloop()
0 Answers
Related