2

一定期間新しいウィンドウを開いてからウィンドウを閉じることになっているPythonコードがあります。このウィンドウは、ボタンをクリックするとトリガーされます。ここに私が持っているものの基本があります。

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()

restoreCallBack ウィンドウを 5 秒間表示してから、ウィンドウを閉じる必要があります。ありがとう!

4

1 に答える 1

4

メソッドをご覧くださいafter。例えば:

widget.after(5000,callback)

GUI(のメインスレッド)でスリープを使用しないでください-全体がフリーズします。

于 2012-06-13T19:30:55.673 に答える