How to create a message box with tkinter?

user46646 picture user46646 · Jun 27, 2009 · Viewed 59k times · Source

I've been trying to build a fairly simple message box in tkinter that has "YES" and "NO" buttons. When I push the "YES" button internally it must go and write YES to a file. Similarly, when "NO" is pushed, NO must be written to a file. How can I do this?

Answer

MatrixFrog picture MatrixFrog · Jun 27, 2009

You can use the module tkMessageBox for Python 2.7 or the corresponding version for Python 3 called tkinter.messagebox.

It looks like askquestion() is exactly the function that you want. It will even return the string "yes" or "no" for you.