2

I have a piece of Python code that is supposed to open a new window for a period of time and then close the window. The window is triggered by clicking a button. Here is the basics of what I have.

def restore(self):
    self.restore = Toplevel()

    message = "Select an available Backup to Restore to."

    Label(self.restore, text=message).pack()
    # We then create and entry widget, pack it and then
    # create two more button widgets as children to the frame.

    os.chdir('.')
    for name in os.listdir("."): 
        if os.path.isdir(name):
            self.button = Button(self.restore, text=name,command=self.restoreCallBack)
            self.button.pack(side=BOTTOM,padx=10)

def restoreCallBack(self):
    self.restoreCB = Toplevel()

    message = "Please wait while the database is restored..."
    Label(self.restoreCB, text=message, padx=100, pady=20).pack()

    time.sleep(5)

    self.restore.destroy()
    self.restoreCB.destroy()

I need the restoreCallBack window to be displayed for 5 seconds, then the windows to close. Thanks!

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Brad Conyers
  • 1,161
  • 4
  • 15
  • 24

1 Answers1

4

Have a look at the after method. e.g.:

widget.after(5000,callback)

You shouldn't use sleep in (the main thread of) a GUI -- The entire thing will just freeze.

mgilson
  • 300,191
  • 65
  • 633
  • 696