This part of my code is the problem: I want to add names to Name_List by entering text into the entry widget. Then use the "add" button to insert the item into Name_List by the function add_name.
import tkinter as tk
from tkinter import *
Name_List = []
...
class NamePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
name=StringVar()
name_entry= tk.Entry(self, text="Enter name:", textvariable=name)
name_entry.pack()
add_button= tk.Button(self, text="Add",
command=lambda: self.add_name(name))
add_button.pack()
To_Role_List= tk.Button(self, text="Assign Roles",
command=lambda: self.print_namelist())
To_Role_List.pack()
def add_name(self,name,i=0):
Name_List.insert(i, name)
print(Name_List)
i+=1
def print_namelist(self):
for i in [0,len(Name_List)]:
print (Name_List[i])
app=TOS_outline()
app.mainloop()
My result, after entering the name "Alpha" into the Entry widget, appears to be this (using print of course):
[<tkinter.StringVar object at 0x03E7D650>]
What do I need to change/fix?