curses: x, y positioning

Ian Clark iclark at mail.ewu.edu
Mon Sep 17 17:55:42 CEST 2007


7stud wrote:
> However, now I am having a problem trying to set the color of the text
> that is output:

import curses

def example(screen):
     if curses.has_colors():
         curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
         curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)
         curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)

         screen.addstr(1, 1, 'Hello', curses.color_pair(1))
         screen.addstr(1, 7, 'World', curses.color_pair(2))
         screen.addstr(1, 12, '!!!', curses.color_pair(3) + curses.A_BOLD)
     else:
         screen.addstr(1, 1, 'You don\'t have colors enabled. :(')

     screen.addstr(3, 0, '<Press any key to continue>')
     screen.refresh()
     screen.getch()

if __name__ == '__main__':
     curses.wrapper(example)

Ian




More information about the Python-list mailing list