我在 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
窗口绘制良好,但当我单击“确定”时,窗口停留在原位,按钮被按下。我正在使用 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()
最佳答案
在从函数返回之前尝试调用 root.update()
。这将处理所有未决的 Tk/X 窗口事件。
(理想情况下,您应该在显示窗口之前建立一个主事件循环,但前提是您的整个程序都是事件驱动的,这可能并不总是有效。)
关于python - 单击“确定”后 Tkinter TkMessageBox 未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17575552/