简体   繁体   中英

Python+tkinter: Text widget doesn't change text immidiately

I have a tk.Text() widget and a button. When the button is clicked, I want to change the text in the Text widget, then conduct a lengthy job. Here is code snippet from the button command function:

price_text.delete("1.0", tk.END)
price_text.insert(tk.END, 'PLEASE WAIT..')  
result = self.the_lengthy_job() 

However, the 'PLEASE WAIT..' message just won't show up until self.the_length_job() returns. Is it possible to get it show before the_length_job() starts?

The problem here is that the window is not being updated after the text is inserted. To fix this, you need to call update() after you create self.price_text() . You can either call self.root.update() or self.price_text.update() , as such:

def do_get(self):
    self.price_text.delete("1.0", tk.END)
    self.price_text.insert(tk.END, "PLEASE WAIT..")
    self.root.update() # Call update() here
    result = self.lengthy_job()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM