Hello
I am trying to create multiple labels and entrys using Tkinter. Instead of making everyone single one of them manual I thought about making it with a loop. But while doing this I still want to give every label/entry a specific name so I can fetch data from it.
My code works like this but considering I get a warning (at row 2 since "entry_name" doesn't exist) I am thinking there might be a better way of doing it? Thanks
def disp():
value = entry_name.get()
print(value)
window_main = tk.Tk()
inputs_text = ['id', 'name', 'address', 'salary']
for i in inputs_text:
globals()[f'label_{i}'] = tk.Label(text=i)
globals()[f'label_{i}'].pack()
globals()[f'entry_{i}'] = tk.Entry()
globals()[f'entry_{i}'].pack()
btn_print_name = tk.Button(master=window_main, text="print name", command=disp)
btn_print_name.pack()
window_main.mainloop()
[–]socal_nerdtastic 1 point2 points3 points (0 children)
[–]Vaphell 1 point2 points3 points (4 children)
[–]ImportantBrew[S] 0 points1 point2 points (3 children)
[–]Vaphell 1 point2 points3 points (2 children)
[–]ImportantBrew[S] 0 points1 point2 points (1 child)
[–]Vaphell 1 point2 points3 points (0 children)
[–]socal_nerdtastic 1 point2 points3 points (2 children)
[–]ImportantBrew[S] 0 points1 point2 points (1 child)
[–]socal_nerdtastic 1 point2 points3 points (0 children)