如何使用python3的curses.window.addch添加颜色?

2024-04-23 13:50:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用python3curses打印彩色输出:

#!/usr/bin/env python3

import curses

def main(stdscr):
    curses.start_color()
    curses.use_default_colors()
    # 0 is always black
    for i in range(0, curses.COLORS):
        curses.init_pair(i + 1, i, -1)

    for i in range(1, curses.COLORS + 1):
        stdscr.addstr("A", curses.color_pair(i))
    stdscr.addch("\n")
    for i in range(1, curses.COLORS + 1):
        stdscr.addch("A", curses.color_pair(i))
    stdscr.addch("\n")
    stdscr.addstr(str(curses.COLORS))
    stdscr.refresh()
    stdscr.getch()

curses.wrapper(main)

但是,在我的系统(urxvt)上,只有第一行是彩色的(使用addstr打印),第二行是白色的。你知道吗

如何解决这个问题?你知道吗


Tags: inforbinmainusrrangecursescolor