1.1 The Python curses module

The original Python curses module was written by Lance Ellinghouse, and is included with the Python source distribution, version 1.5 or earlier. It supports all the basic operations of displaying text, but doesn't support System V features such as colour. Later, Oliver Andrich enhanced this module by adding support for many of the missing features.

Both modules are a fairly simple wrapper over the C functions provided by curses; if you're already familiar with curses programming in C, it's really easy to transfer that knowledge to Python. The biggest difference is that the Python interface makes things simpler, by merging different C functions such as addstr, mvaddstr, mvwaddstr, into a single addstr() method. You'll see this covered in more detail later.

This HOWTO is simply an introduction to writing text-mode programs with curses and Python, and doesn't even attempt to be a complete guide to the curses API. It will, however, give you the basic ideas. This documentation doesn't even cover every single curses function available in the Python modules; that would make this a very long HOWTO, and would duplicate much of the information in the curses documentation. You should consult the documentation for your curses implementation to learn about its quirks.

To install the regular curses extension, you only have to uncomment the corresponding line of Modules/Setup in your Python source tree, and recompile. You may have to tweak the required libraries, as described in the comment:

# Lance's curses module.  This requires the System V version of
# curses, sometimes known as ncurses (e.g. on Linux, link with
# -lncurses instead of -lcurses; on SunOS 4.1.3, insert
# -I/usr/5include -L/usr/5lib before -lcurses).

curses cursesmodule.c -lcurses -ltermcap

To install the newer module, fetch the most recent version from http://andrich.net/python/selfmade.html#ncursesmodule, unpack it, and simply run make.