1

I am looking to call a function that updates a textbox when I pass a string through a queue. This function resides in a class called UpdateGUI, which contains the initialization of the textbox and other functions.

My problem: The code will not update the new string into the textbox. It might be that the code does not insert anything as well, but when I debug it the insert line of code passes, while putting in

    self.tbCopyStatus.update_idletasks()

falls out. I have looked at several examples, but the code never seems to work.

Here's the class UpdateGUI:

class UpdateGUI(Frame):

    def __init__(self):
        Frame.__init__(self)
        self.wdwCopyStatus = Tk()
        self.wdwCopyStatus.title('VMs Completed')
        self.wdwCopyStatus.geometry("960x600")
        self.sbarCopyStatus = Scrollbar(self.wdwCopyStatus)
        self.sbarCopyStatus.pack(side=RIGHT, fill=Y)
        self.tbCopyStatus = Text(self.wdwCopyStatus, width=120, height=60, yscrollcommand= self.sbarCopyStatus.set, cursor="arrow", wrap=WORD)
        self.sbarCopyStatus.config(command=self.tbCopyStatus.yview)
        self.tbCopyStatus.pack(side=LEFT, fill=BOTH)
        self.now = datetime.datetime.now()
        self.tbCopyStatus.insert(END, self.now.strftime("%m/%d/%Y  %H:%M") + "\n")

    def updateRecord(self):
        while not queue.empty():
            string = queue.get()
            self.tbCopyStatus.insert(END, string)
            queue.task_done()
            #I want to update the text box here
        else:
            pass

    def finished(self):
        self.tbCopyStatus.config(state=DISABLED)
        content = self.tbCopyStatus.get(1.0, END)
        queue.put(content)

The thread talks to the class' functions just fine, which leads me to believe that there's a bug communicating between the UpdateRecord() function and the main __init__ function.

Thank you in advanced for reading this and helping me with this problem!

NorthCat
  • 9,643
  • 16
  • 47
  • 50
  • Are you running the mainloop in your program? – Bryan Oakley Aug 11 '14 at 21:17
  • What do you mean by, "falls out" on update_idletasks? I once had this problem and it looks similar: http://stackoverflow.com/questions/13795265/odd-function-behavior-with-tkinter-python – nair.ashvin Aug 12 '14 at 15:15

0 Answers0