2008-11-29 41 views
4

我使用類似於: screen.addstr(text,color_pair(1)| A_BOLD),但它似乎不起作用.. 但是,A_REVERSE和所有其他屬性確實有用!屬性BOLD在我的詛咒中似乎不起作用

事實上,我試圖用白色打印一些東西,但是COLOR_WHITE將它打印成灰色......並且在搜索一段時間之後,似乎將它打印爲灰色+大膽使它成爲可能!

任何幫助將不勝感激。

回答

5

下面是一個例子代碼(Python 2.6中,Linux的):

#!/usr/bin/env python 
from itertools import cycle 
import curses, contextlib, time 

@contextlib.contextmanager 
def curses_screen(): 
    """Contextmanager's version of curses.wrapper().""" 
    try: 
     stdscr=curses.initscr() 
     curses.noecho() 
     curses.cbreak() 
     stdscr.keypad(1) 
     try: curses.start_color() 
     except: pass 

     yield stdscr 
    finally: 
     stdscr.keypad(0) 
     curses.echo() 
     curses.nocbreak() 
     curses.endwin() 

if __name__=="__main__": 
    with curses_screen() as stdscr: 
     c = curses.A_BOLD 
     if curses.has_colors(): 
      curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) 
      c |= curses.color_pair(1) 

     curses.curs_set(0) # make cursor invisible 

     y, x = stdscr.getmaxyx() 
     for col in cycle((c, curses.A_BOLD)): 
      stdscr.erase() 
      stdscr.addstr(y//2, x//2, 'abc', col) 
      stdscr.refresh() 
      time.sleep(1) 

一切似乎是工作。