python - Not able to change colours in curses on windows -
i using curses on windows here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses using 32 bit build python 3.4
it's been working far except colours. reports can alter colours, when trying alter colours, nil happens. limitation of curses windows or problem code?
import curses def main(stdscr): curses.start_color() stdscr.addstr("can alter color? %s\n" % str(curses.can_change_color())) in range(0, curses.colors): curses.init_color(i, 1000, 0, 0) curses.init_pair(i + 1, i, 0) try: in range(0, 255): stdscr.addstr(str(i), curses.color_pair(i)) except curses.err: pass stdscr.getch() curses.wrapper(main)
in this, reports can alter colours, when trying set every colour reddish (as test), remain default.
i know been quite while since asked question, since 1 of first hits google search "python curses color issues", thought may reply this.
this linked answer contains exact solution looking for. don't phone call curses.color_pair(i)
directly, have define pairs first:
stdscr = curses.initscr() curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.color_red, curses.color_white) stdscr.addstr( "pretty text", curses.color_pair(1) ) stdscr.refresh()
the above code display word "pretty text" in reddish color , white background (but create sure console supports coloring calling curses.has_colors()
first.
python windows colors ncurses curses
No comments:
Post a Comment