pythondialog

Made with Python.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).

Example

The following example is written for pythondialog 3, because it uses d.OK (attribute of the Dialog class accessed through the d Dialog instance), which was introduced in pythondialog 3. If you want it to work with pythondialog 2, simply replace all occurrences of d.OK with d.DIALOG_OK.

Note: the (very!) old syntax (d.DIALOG_OK) still works in pythondialog 3, but is deprecated.

#! /usr/bin/env python3

import locale
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

which gives:

For more examples, see simple_example.py and demo.py in a release tarball.

News

The main changes between the various pythondialog releases are described on the news page.

Installation

Debian users: the package containing pythondialog can be installed with:

apt-get install python3-dialog

Other Linux distributions such as Gentoo may also propose pythondialog from their software repositories.

Very old versions that have not been uploaded to PyPI can be found on the SourceForge download page and on Florent Rougon's home page.

Links pertaining to pythondialog:

pythondialog relies heavily on these two projects:

History and status

pythondialog was created by Robb Shecter <robb@acm.org> around year 2000, then maintained:

Its current maintainer is Florent Rougon.