Problems with curses.start_color()

skip at pobox.com skip at pobox.com
Tue Apr 10 15:01:26 EDT 2007


Environment: Solaris 10, Python 2.4.2.

I'm trying to convert a very simple (display-wise) program to use curses.
This is my first try at using curses.  I have wrapped my main:

    try:
        sys.exit(curses.wrapper(main, *sys.argv[1:]))
    except (KeyboardInterrupt, SystemExit):
        sys.exit(0)

According to the docs, curses.wrapper() calls curses.start_color(), but if I
don't call it myself I get this traceback when I try to use colors:

    Traceback (most recent call last):
      File "snake/scripts/message-tracker.py", line 141, in display
      attr = curses.color_pair(0)
    error: must call start_color() first

If I call start_color() unconditionally I get this error:

    Traceback (most recent call last):
      File "snake/scripts/message-tracker.py", line 229, in ?
        sys.exit(curses.wrapper(main, *sys.argv[1:]))
      File "/opt/app/g++lib6/python-2.4/lib/python2.4/curses/wrapper.py", line 44, in wrapper
        return func(stdscr, *args, **kwds)
      File "snake/scripts/message-tracker.py", line 215, in main
        curses.start_color()
      File "/opt/app/g++lib6/python-2.4/lib/python2.4/curses/__init__.py", line 41, in start_color
        retval = _curses.start_color()
    error: start_color() returned ERR

If I protect the call like so:

    try:
        curses.start_color()
    except:
        pass

I get the first traceback again.

A quick Google search didn't turn this up as an obvious problem.  What have
I missed?

Thx,

Skip



More information about the Python-list mailing list