Message boxes
While less common nowadays, there is still a lot of value in being able to create interactive character-based user interfaces, especially when just a simple message dialog with an OK button or an OK/cancel dialog is needed; you can achieve a better result by directing the user's attention to them through a nice-looking text dialog.
Getting ready
The curses
library is only included, in Python for Unix systems, so Windows users might need a solution, such as CygWin or the Linux Subsystem for Windows, to be able to have a Python setup that includes curses
support.
How to do it...
For this recipe, perform the following steps:
- We will make a
MessageBox.show
method which we can use to show a message box whenever we need it. TheMessageBox
class will be able to show message boxes with just OK or OK/cancel buttons:
import curses import textwrap import itertools class MessageBox(object): @classmethod def show(cls, message, cancel=False, width=40): """Show a message with...