Skip to content Skip to sidebar Skip to footer

Keep Tkinter Progressbar Running Until A File Is Created

I'm trying to put a info popup window to the user to advise him that a file is being created and that he must wait until it's created. I've a master frame that creates a popup wind

Solution 1:

while loop cause the UI unreponsive.

Use Widget.after instead to periodically checkfile method.

definitUI(self):
    self.popup = popup = Toplevel(self)
    Label(popup, text="Please wait until the file is created").grid(
        row=0, column=0)
    self.progressbar = progressbar = ttk.Progressbar(popup,
        orient=HORIZONTAL, length=200, mode='indeterminate')
    progressbar.grid(row=1, column=0)
    progressbar.start()
    self.checkfile()

defcheckfile(self):
    if os.path.exists("myfile.txt"):
        print'found it'
        self.progressbar.stop()
        self.popup.destroy()
    else:
        print'not created yet'
        self.after(100, self.checkfile) # Call this method after 100 ms.

What modified:

  • Used after instead of while loop.
  • Made progressbar, popup accessible in checkfile method by making them instance attribute.
  • Moved progressbar.stop, popup.destroy to checkfile method.

Post a Comment for "Keep Tkinter Progressbar Running Until A File Is Created"