I am writing a Tkinter program and have a root where a labels are displayed next to entry widgets.
EX: Name -> SearchTerm ENTRY BOX
I am trying to create a list of values from entry wigets (EX: ['', 'user input', 'user input'])
I have created the entry widgets in the root and then have a function that gets the values:
def get_user_entries(user_entries):
new_search_terms = []
for entry in user_entries:
new_search_terms.append(entry.get())
return new_search_terms
I want to be able to access the list called new_search_terms in order to run another python program on it.
I have tried to use the function as the command for a button. I have tried binding the button in different places. I have tried invoking the button in different places. I also tried creating a class where I new_search_terms was a class variable, but since I can't access the returned information from the function above the updated class variable did not hold. After exhausting the internet and several books I have yet to find an example where information is returned out of a Button function rather than printed. I need to be able to access this information in another place.
Is there a way to access the information I need or is there another approach to this in Tkinter I haven't thought of?
The code where I create the button:
done = Button(root, text='Done', command= lambda: get_user_entries(user_entries))
done.pack()
Here is the code that created the entries and labels:
def uc_1(original_names, final_names, root):
user_entries = []
for index in range(len(original_names)):
row = Frame(root)
info = Label(row, text = original_names[index]+'->'+final_names[index])
user_entry = Entry(row)
row.pack(side=TOP, fill=X)
user_entry.pack(side=RIGHT, expand=YES, fill=X)
user_entries.append(user_entry)
info.pack(side=LEFT)
return user_entries
Thanks!