I would like to generate my python GUI at runtime Imagine the list being some data coming from a database, and I want buttons for every db line. How do I make this work?
import tkinter as tk
root = tk.Tk()
root.geometry("800x480")
def cmdLastafel(button):
button["text"] = "deze"
lst= ["A","B","C"]
cnt = 0
for i in lst:
cnt +=1
btn = tk.Button(root)
btn["text"] = i
btn.configure(command=lambda: cmdLastafel(btn))
btn.grid(row=cnt,column=0)
root.mainloop()
This gives me 3 buttons but when I press A, C text is changed.. I have a .net background, and there I would solve it by creating a new button at beginning of for loop, and storing the button in a list at the end of the loop. But I don't knwo how to force a new in python, or how to create an empty list of buttons..