May-12-2020, 02:39 PM
(This post was last modified: May-12-2020, 02:39 PM by deanhystad.)
A couple of problems here. You are creating new StringVars every time you call give_values so there is no way these can be bound to an Entry. Even if you only created the StringVar's once, their attribute names (varXX) do not exist outside the function give_values, so you would have no way to get these variables and bind them to the entries. Finally, you cannot set textvariable="var00" and expect the Entry constructor to figure out which namespace to use to search for attribute "var00" and get a StringVar.
import tkinter as tk from tkinter import * root = tk.Tk() variables = [] def give_values(): return [var.get() for var in variables] # Makes a list calling get for each StringVar in variables def init(): for i in range(3): for j in range(3): frame = tk.Frame( master=root, relief=tk.RAISED, width=2, borderwidth=1 ) frame.grid(row=i, column=j) var = StringVar() variables.append(var) entry = tk.Entry(master=frame, text=f"Row {i}\nColumn {j}", textvariable=var) entry.pack() init() # b1 = Button(root, text="Done", width=10).grid(row=0, column=10, rowspan=10) # command=done) b2 = Button(root, text="Enter", width=10, command=give_values).grid(row=1, column=10, rowspan=10) # command=enter()) root.mainloop()