单击"确定"后,Tkinter TkMessageBox未关闭

Rqo*_*mey 6 python tkinter xfce python-2.7

我用Python创建了一个脚本,它在给定的事件中通知我.我使用以下函数来生成警告窗口:

def window_warn():
    '''
    This function will throw up a window with some text
    '''
    #These two lines get rid of tk root window
    root = Tkinter.Tk()
    root.withdraw()
    #tkMessageBox.deiconify() 
    TkMessageBox.showwarning("New Case", "You have a new case\n Please restart pycheck")
    return
Run Code Online (Sandbox Code Playgroud)

窗口绘制正常,但是当我单击确定时,窗口会在按下按钮的情况下保持原位.我正在使用xfce.无论如何在点击确定后让窗口关闭?

评论表明这可能与周围的代码有关,所以为了完整性:

print "Just started newcase check"
while True:
    if "Uncommitted" in webpage:
        print "oh look, 'Uncommitted' is in the url returned from the last function"
        #If this hits we call a notification window
        window_warn()
        print "sleeping"
        time.sleep(10)

        webpage = scrape_page()
    else:
        print "nothing"
        time.sleep(20)
        webpage = scrape_page()
Run Code Online (Sandbox Code Playgroud)

Fre*_*rik 6

root.update()在从函数返回之前尝试调用.这将处理所有待处理的Tk/X窗口事件.

(理想情况下,您在显示窗口之前建立一个主事件循环,但这假定您的整个程序是事件驱动的,这可能并不总是有效.)