A minimal program using pythondialog starts with the creation of a Dialog instance:
import dialog
from dialog import Dialog
d = Dialog(dialog="dialog")
The dialog parameter indicates the executable to use to invoke the backend (which must be compatible with dialog). For instance, one might use something like dialog="/home/dave/src/dialog-1.2-20140219/dialog". The default value is "dialog", and since it does not contain any slash (/), it is looked up in the PATH. See Dialog.__init__() for a description of all parameters that can be passed to the Dialog constructor.
Once you have a Dialog instance, you can call any widget-producing method, as documented in The Dialog widgets. For instance, if you want to display a menu offering three choices:
code, tag = d.menu("Some text that will be displayed before the menu entries",
choices=[("Tag 1", "Item text 1"),
("Tag 2", "Item text 2"),
("Tag 3", "Item text 3")])
When the method returns:
- code will be equal to d.OK if there was no error and the user chose an entry (instead of pressing Esc). See “Dialog exit code” (high-level) for more details on how to interpret code.
- tag will contain the name of the tag corresponding to the selected entry: "Tag 1", "Tag 2" or "Tag 3" (assuming that code == d.OK).
A simple example using Dialog.menu()
For a slightly lengthier example, you can look at the simple_example.py file that comes with pythondialog, in the examples directory. It is a very simple and straightforward example using a few basic widgets. The pythondialog website also has a very simple example that can be used to get started.
Once you are comfortable with the basics, you can study the demo.py file that illustrates most features of pythondialog (also from the examples directory), or more directly dialog.py.