Simple Popup Requester in Python

Sometimes I think I should change the name of this blog to Mind Like a Sieve, subtitle Straining to Remember.

I’ve built some miscellaneous one-off GUIs with various Python toolkits like Tkinter and wxPython, but this time I wanted just a simple confirmation popup.  In this case it was to pause so I could attach a debugger.

The comment on this page of the tkinterbook had exactly what I needed.  Also, there is a page showing examples of all the different simple popups you can make using this approach.  One benefit of using this approach is that Tkinter is bundled with Python, so there are no additional packages to install.

Here’s the simplest code snippet:

import Tkinter, tkMessageBox
Tkinter.Tk().withdraw() # suppress blank Tk root window in Windows
tkMessageBox.showinfo("Debugging", "Attach debugger, then click OK")

You can, of course, get much fancier with some of the popup versions, and you can capture the return value from the user interaction.

Tags: , , ,

Leave a Reply