Chapter 13. User Interfaces

The Principle of Least Astonishment: Make a user interface as consistent and as predictable as possible.

Anonymous

Unless an application is deeply embedded, or specifically designed to run as a background process, it will probably need some type of user interface. In this chapter we will explore different ways to communicate with a user. We’ll start by examining what you can do with just the command line. Next we’ll look at how to use an ANSI-capable terminal emulator program to display data and accept input, and then the curses screen control package for Python. After this we’ll move to the realm of bright colors, fancy graphs, images, and dialogs, with a look at the TkInter GUI toolkit provided with the standard Python distribution. We’ll also take a quick tour of the wxPython GUI package.

Text-Based Interfaces

Text-based interfaces are the foundation of all display-based computer user interfaces. I say display-based because technically, the first interfaces were panels full of lights and switches. Printing terminals came next, but it wasn’t until the advent of CRT terminals that human-machine interface (HMI) devices began to come into their own.

The Console

The most straightforward way to interact with any program, Python or otherwise, is through the console interface. Under Windows this is the so-called “DOS box,” or the “cmd prompt” as it’s currently known (the Windows shell application is called cmd.exe). On a Unix or Linux system it is the shell prompt ...

Get Real World Instrumentation with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.