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 is new 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 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

which gives:

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).

News

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

Installation

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.

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.