how to update a listbox in one window in one class using a different class python
Question: what i have is a window that opens up and it has a list box. this is created
using one class. when i click the search button and results are found using a
different class, i want the list box to update without having to open up
another window. below is my code so far\n

    
    
    from Tkinter import *
    
    
    class addTask:
        def __init__(self):
            self.addWindow = Tk()
            self.addWindow.configure(background = "black")
            self.addWindow.geometry("450x450")
            self.addWindow.resizable(width = False, height = False)
            self.addWindow.title("Add Task")
    
            self.addNameLabel = Label(self.addWindow,text="Add the name of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
            self.addNameLabel.place(relx=0.01, rely=0.05)
            self.nameWiget = Text (self.addWindow, width = 63, height = 1)
            self.nameWiget.place(relx=0.0, rely=0.1)
    
            self.addDateLabel = Label(self.addWindow,text="Add the date of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
            self.addDateLabel.place(relx=0.01, rely=0.2)
            self.dateWiget = Text (self.addWindow, width = 63, height = 1)
            self.dateWiget.place(relx=0.0, rely=0.25)
    
            self.addTaskLabel = Label(self.addWindow,text="Add the details of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
            self.addTaskLabel.place(relx=0.01, rely=0.35)
            self.taskWiget = Text (self.addWindow, width = 63, height = 1)
            self.taskWiget.place(relx=0.0, rely=0.4)
    
            addButton = Button(self.addWindow,height = 5, width = 20, text="Add Task",highlightbackground="black",font=("Helvetica",10,"bold"),command=lambda:self.saveFuntion())
            addButton.place(relx=0.25, rely=0.55)
    
    
        def saveFuntion(self):
            nameInfo = (self.nameWiget.get(1.0, END))
            dateInfo = self.dateWiget.get(1.0, END)
            taskInfo = self.taskWiget.get(1.0, END)
            print nameInfo
            task1 = Task(nameInfo,dateInfo,taskInfo)
            task1.save()
            self.nameWiget.delete(1.0,END)
    
    class Task:
        def __init__(self,name,date,task):
            self.__name = name
            self.__date = date
            self.__task = task
    
    
        def save(self):
            fileName = open("dataFile.txt","a")
            fileName.write(self.__name)
            fileName.write(self.__date)
            fileName.write(self.__task)
    
    class editTask:
        def __init__(self):
            self.editWindow = Tk()
            self.newWindow = Tk()
            self.newWindow.geometry("450x750")
            self.editWindow.configure(background = "black")
            self.editWindow.geometry("450x750")
            self.editWindow.resizable(width = False, height = False)
            self.editWindow.title("Edit Task")
            self.listBox = Listbox(self.editWindow,heigh = 15, width = 30)
            self.listBox.place(relx = 0.2, rely = 0.6)
    
            #drop down menu
            self.var = StringVar(self.editWindow)
            self.var.set("Select search critria")
            self.choices = ["Name","Date"]
            self.option = OptionMenu(self.editWindow,self.var,*self.choices)
            self.option.configure(bg = "black")
            self.option.place(relx = 0.5, rely = 0.2)
    
            #edit label and text box
            self.editLabel = Label(self.editWindow,text="Add the name of the task",font = ("Helvetica",10,"italic"),bg = "black",fg = "white")
            self.editLabel.place(relx=0.01, rely=0.05)
            self.editInfoWiget = Text (self.editWindow, width = 63, height = 1)
            self.editInfoWiget.place(relx=0.0, rely=0.1)
    
            # search button
            searchButton = Button(self.editWindow,height = 5, width = 20, text="Search for Task",highlightbackground="black",font=("Helvetica",10,"bold"),command=lambda:self.searchFuntion())
            searchButton.place(relx=0.3, rely=0.4)
    
        def searchFuntion(self):
    
            critria = self.var.get()
            info = self.editInfoWiget.get(1.0,END)
            thing = info.split("\n")
            thing2  = thing[0]
    
    
            search = searchCritria(critria,thing2)
            search.search()
    
    
        #    def openListBox(self):
    
    
    
    
    
    
    class searchCritria():
    
        def __init__(self,critria,info):
            self.__critria = critria
            self.__info = info
    
        def search(self):
            self.file = open("dataFile.txt", "r+")
            fileData = self.file.readlines()
            self.file.close()
    
            lengthOfFile = len(fileData)
            counter = 1
            self.name = []
            self.date = []
            self.details = []
    
            for i in range (lengthOfFile):
                split = fileData[i].split("\n")
                while counter == 1:
                    self.name.append(split)
                    break
                while counter == 2:
                    self.date.append(split)
                    break
                while counter == 3:
                    self.details.append(split)
                    break
                counter = counter +1
                if counter > 3:
                    counter = 1
    
            if self.__critria == "Name":
                for x in range (len(self.name)):
                    self.taskName = self.name[x]
                    self.taskName2 = self.taskName[0]
                    if self.__info == self.taskName2:
                        openWindow = True
                    else :
                        openWindow = False
                if openWindow == True:
                    editTask().listBox.insert(END,self.taskName2)
    
            if self.__critria == "Date":
                for x in range (len(self.date)):
                    self.taskDate = self.date[x]
                    self.taskDate2 = self.taskDate[0]
                    if self.__info == self.taskDate2:
                        print "found"
                    else :
                        print"not found"
    class editTask2():
        def __init__(self):
            self.edit2Window = Tk()
            self.edit2Window.configure(background = "black")
            self.edit2Window.geometry("450x350")
            self.edit2Window.resizable(width = False, height = False)
            self.edit2Window.title("Edit Task")
    

any help would be great

thanks


Answer: The biggest problem in your code is that you're creating multiple instances of
`Tk`. Tkinter simply isn't designed to work that way. You should only ever
create a single instance of `Tk`. If you need additional windows, create
instances of `Toplevel`.

Also, you need to call the `mainloop` function of this instance of `Tk`
exactly once. Without it, your GUI will not work.

If you want to update a listbox in another class than where it was created,
the concept is pretty simple: if A needs to update B, A needs a reference to
B. So, either pass in a reference to the listbox when you create the other
class, or give the other class a method you can call where you pass in the
reference to the listbox after it was created.

