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!