pythondialog is a Python wrapper for the dialog utility originally written by Savio Lam, and later rewritten by Thomas E. Dickey. Its purpose is to provide an easy to use, pythonic and comprehensive Python interface to dialog. This allows one to make simple text-mode user interfaces on Unix-like systems (including Linux).
The following example is written for pythondialog 3, because it
d.OK (attribute of the
Dialog class accessed
through the d
Dialog instance), which is new in
pythondialog 3. If you want it to work with pythondialog 2,
simply replace all occurrences of
Note: the old syntax (
d.DIALOG_OK) still works in
pythondialog 3, but is deprecated.
#! /usr/bin/env python3 import locale, dialog from dialog import Dialog # This is almost always a good thing to do at the beginning of your programs. locale.setlocale(locale.LC_ALL, '') # You may want to use 'autowidgetsize=True' here (requires pythondialog >= 3.1) d = Dialog(dialog="dialog") # Dialog.set_background_title() requires pythondialog 2.13 or later d.set_background_title("My little program") # For older versions, you can use: # d.add_persistent_args(["--backtitle", "My little program"]) # In pythondialog 3.x, you can compare the return code to d.OK, Dialog.OK or # "ok" (same object). In pythondialog 2.x, you have to use d.DIALOG_OK, which # is deprecated since version 3.0.0. if d.yesno("Are you REALLY sure you want to see this?") == d.OK: d.msgbox("You have been warned...") # We could put non-empty items here (not only the tag for each entry) code, tags = d.checklist("What sandwich toppings do you like?", choices=[("Catsup", "", False), ("Mustard", "", False), ("Pesto", "", False), ("Mayonnaise", "", True), ("Horse radish","", True), ("Sun-dried tomatoes", "", True)], title="Do you prefer ham or spam?", backtitle="And now, for something " "completely different...") if code == d.OK: # 'tags' now contains a list of the toppings chosen by the user pass else: code, tag = d.menu("OK, then you have two options:", choices=[("(1)", "Leave this fascinating example"), ("(2)", "Leave this fascinating example")]) if code == d.OK: # 'tag' is now either "(1)" or "(2)" pass
For more examples, see simple_example.py and demo.py in a release tarball (simple_example.py is only included in versions 2.14.0 and later).
The main changes between the various pythondialog releases are described on the news page.
- For the reference implementation (which is written for Python 3), go to the PyPI page for pythondialog.
- For the Python 2 backport, recent versions are available on the PyPI page for the Python 2 backport of pythondialog.
A Debian package for Python 3 in sid is available in the following APT repository signed by Florent Rougon's OpenPGP key:
deb http://people.via.ecp.fr/~flo/debian unstable main deb-src http://people.via.ecp.fr/~flo/debian unstable main
Note: if you add this repository to your /etc/apt/sources.list, beware that it may contain (and thus might propose to upgrade) other packages.
Links pertaining to pythondialog:
- PyPI entry for pythondialog (PyPI being the Python Package Index)
- PyPI entry for the Python 2 backport of pythondialog
- SourceForge download page
- SourceForge project page
- Git repository
- pythondialog Manual rendered by Sphinx
- Mailing list
- Issue tracker (for bug reports, feature requests and patch proposals)
pythondialog relies heavily on these two projects:
History and status
pythondialog was created by Robb Shecter <email@example.com> around year 2000, then maintained:
- by Florent Rougon from 2002 to 2004 at his home page;
- by Peter Åstrand from 2004 to 2009 at SourceForge;
- again by Florent Rougon from 2009 to 2013 at his home page and from August 2013 onwards at SourceForge.
Its current maintainer is Florent Rougon.