Question

I'm using Progressbar on a popup window of my UI to notify the user that has to wait 10 seconds to do other stuff with the UI.

How can I add a sleep(10) or something similar to code so it doesn't get stuck?

window3 = Toplevel(self) 
self.textoBar = Label(window3, text="Doing stuff, please, wait 5 seconds")
self.textoBar.grid(row=0, column=0, pady=(5,5))
self.progressbar = ttk.Progressbar(window3, orient = HORIZONTAL, mode = 'indeterminate',length=250)
self.progressbar.grid(row=1, column=0, pady=(5,5))
self.progressbar.start()
# wait 10 seconds
self.progressbar.stop()
window3.destroy()

Thanks in advance.

Was it helpful?

Solution

Use after to schedule a function to run in the future. The first argument is an amount of time in milliseconds, the second argument is a callable function.

def stop_progressbar(self):
    self.progressbar.stop()

self.after(10000, self.stop_progressbar)

Of course, you'll want to call your window3.destroy function in a similar way, or within the stop_progressbar function so it doesn't run while the system is waiting to stop the progressbar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top