0

I have a little problem with a Tkinter program. So I am trying to create a GUI and I want to create a known number of buttons but too long to asigne each one individually. To create the buttons I have no problem, but I want that each button makes a special thing. To do so I used lambda in order to be able to give the command a parameter. But the problem is that the program takes into account the last value of "x" (here in my program) and here I really do not know how to solve this problem. When I enter the parameters manually it works, but I can no do it for 40 buttons (it will probably be more than 100 at the end of the program).

Thank you in advance for your help
Here is my code:

Boite_RN = Frame(window, bg=couleur)


h = {}
x = 0
for j in range(int(10)):
    for i in range(4):
        h[d[x]] = Button(Boite_RN, text=d[x], font=("Times", 15), bg="#2752F2", fg="white", height=3,
              width=6, command=lambda : et(x))
        h[d[x]].grid(row=i, column=j, padx=2, pady=2)
        x += 1
Boite_RN.pack(pady=40)

0 Answers0