<p>I’ve writen a little python script that just pops up a message box containing the text passed on the command line. I want to pop it up only when the window —resulting from a previous call— is not open.</p>

<pre><code>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:]))
</code></pre>

<p>Any idea how to check that?</p>

[{'answer_id': 46205, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I believe you want:</p>\n\n<pre><code>if \'normal\' != root.state():\n    tkMessageBox.showinfo("Key you!", " ".join(sys.argv[1:]))\n</code></pre>\n'}, {'answer_id': 47374939, 'author': 'Billal Begueradj', 'author_id': 3329664, 'author_profile': 'https://Stackoverflow.com/users/3329664', 'pm_score': 0, 'selected': False, 'text': '<p>The previous answer works accordingly to the code you have provided. You say it does not work because the answerer complies with "sois bête et discipliné" rule in that he did not add <code>root.mainloop()</code> to his code since your question does not either.</p>\n\n<p>By adding the later line, for some reason caused by the event loop, you should test the exact string "withdrawn" as follows:</p>\n\n<pre><code>import tkinter as tk\nfrom tkinter import messagebox\nimport sys\n\n\nroot = tk.Tk()\nroot.withdraw()\n\nif \'withdrawn\' != root.state():\n   messagebox.showinfo("Key you!", sys.argv[1:])\n\n\nroot.mainloop()\n</code></pre>\n\n<p>Note: do not run this code otherwise your Terminal session will hang up. To circumvent this discomfort, you will have to reset the window state using either <code>root.state("normal")</code> which will lead to the message box to disappear as if a click on the Ok button occurred, or <code>root.iconify()</code> through which you can stop the Terminal session to hang up by right clicking on the tkinter icon appearing on your OS taskbar.</p>\n'}]
['https://Stackoverflow.com/questions/45540', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4717/']