单击确定后,Tkinter TkMessageBox无法关闭 [英] Tkinter TkMessageBox not closing after click OK

查看:652
本文介绍了单击确定后,Tkinter TkMessageBox无法关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Python创建了一个脚本,该脚本会在给定事件时通知我. 我正在使用以下功能来生成警告窗口:

I have created a script in Python which notifies me at a given event. I am using the following function to produce the warning window:

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

该窗口可以很好地绘制,但是当我单击确定"时,该窗口将保持在原位,并且按下该按钮.我正在使用xfce. 无论如何,单击确定后是否可以关闭窗口?

The window draws fine, but when I click ok, the window stays in place with the button depressed. Im using xfce. Is there anyway to get the window to close after ok is clicked?

评论表明这可能与周围的代码有关,因此出于完整性考虑:

A comment indicated this may be to do with surrounding code, so for completeness:

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

推荐答案

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

Try calling root.update() before returning from the function. That will process all pending Tk/X window events.

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

(ideally, you'd establish a main event loop before displaying the window, but that assumes that your entire program is event driven, which may not always work.)

这篇关于单击确定后,Tkinter TkMessageBox无法关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆