如何知道Tk中是否已经打开具有给定标题的窗口?

时间:2020-03-05 18:48:08  来源:igfitidea点击:

香港专业教育学院写了一个小的python脚本,只是弹出一个消息框,其中包含在命令行上传递的文本。我只想在上一个调用导致的窗口未打开时才弹出它。

from Tkinter import *
import tkMessageBox

root = Tk()
root.withdraw() 

# TODO not if a window with this title exists
tkMessageBox.showinfo("Key you!", " ".join(sys.argv[1:]))

知道如何检查吗?

解决方案

回答

我相信你想要:

if 'normal' != root.state():
    tkMessageBox.showinfo("Key you!", " ".join(sys.argv[1:]))