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 root.mainloop()
to his code since your question does not either.
By adding the later line, for some reason caused by the event loop, you should test the exact string "withdrawn" as follows:
import tkinter as tk
from tkinter import messagebox
import sys
root = tk.Tk()
root.withdraw()
if 'withdrawn' != root.state():
messagebox.showinfo("Key you!", sys.argv[1:])
root.mainloop()
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 root.state("normal")
which will lead to the message box to disappear as if a click on the Ok button occurred, or root.iconify()
through which you can stop the Terminal session to hang up by right clicking on the tkinter icon appearing on your OS taskbar.