Tkinter name widgets in a loop Tkinter name widgets in a loop tkinter tkinter

Tkinter name widgets in a loop


You can use a list to hold the entry values and after a loop to read them.This is what I usually do.

Try:

entries_list = []for x in range(1, 22):            for y in range(4, 9):                e  = tk.Text(self,                             height=1,                             width=3)                e.grid(column=x,                       row=y)                entries_list.append(e)

and after:

for x in entries_list:    x.get(1.0, END)


In this case, I'd use a dictionary as it would allow you to reference the widgets according to their grid position. You could do this like so:

text_widgets = {}for x in range(1, 22):    for y in range(4, 9):        e  = tk.Text(self,                     height=1,                     width=3)        e.grid(column=x,               row=y)        text_widgets[(x, y)] = e

This allows you to access the widgets positionally at a later time - so, if you wanted the value of the widget in column 10, row 7 you could access it by using:

text_widgets[(10, 7)].get('1.0', 'end-1c')