1

I have a funtion, that parses the log. I am updating the label color and text at different lines within the same funtion. I see that only the last changed color and text only reflecting in the UI. i do not see the intermediate color and text changes.

Below is my code:

def OnclickLogParser(self):
    if LogFileName == '':
        messagebox.showinfo("Error", "Please select a valid Log")
    if LogPathName == '':
        messagebox.showinfo("Error", "Please select a valid Log Path")
    self.lb_log_status.configure(bg="#08DFE8", fg="#010101", text='Parsing inProgress...')
    m_logParser = CAdpBrrLogParser()
    m_logReader = CAdpBrrLogReader('mrr', m_logParser)
    status = m_logReader.readFile(LogPathName)
    if status == True:
        self.lb_log_status.configure(bg="#F6F50B", fg="#010101", text='Log Ready')
        self.btn_log_start["state"] = "normal"
    global m_injector
    m_injector = CAdpUdpDataInjector()

you can see that i am changing the color and text of lb_log_status at two different places. The time gap between those two lines would be around 3 -5 secs. But i can not witness the first color change. '

deepan
  • 47
  • 4

1 Answers1

0

Tkinter must process events regularly to perform any UI operations. If you want to see the color changes here you have to give Tk a chance to process the configuration and paint events that get generated when you re-configure a widget. Your code just immediately starts processing the log and will not process any events until this function exits and you return to the Tk mainloop() which is the event processing method. You would see the same problem if you used a progress bar widget and tried to update the progress during processing.

One way to resolve this is to use the Tk after() method and schedule your processing in chunks that take a limited amount of time per chunk. After reading and processing a chunk call after() again to schedule the next chunk.

Another method is to put the processing on a worker thread and use event_generate() to post events back to the Tk thread to announce progress and completion.

patthoyts
  • 32,320
  • 3
  • 62
  • 93