为什么这段 python 代码没有生成正常的 black
背景色?
import curses
def func(stdscr):
c = stdscr.getkey()
curses.wrapper(func)
我真的不明白。我尝试了很多东西(color_pair
、pair_number
、init_pair
等)。这真的不黑。
我使用的是默认的 ubuntu gnome 终端。 (但据我所知,这没有什么区别)。
最佳答案
除非您手动指定颜色,否则 curses 将遵循您的终端调色板。大多数终端将使用 .Xresources 或 .Xdefaults 文件中的设置(不确定 gnome 终端)
但是如果你想手动定义你的颜色。使用 curses.init_color,这并不适用于所有终端,有关其用法的更多信息,请参见 python curses documentation .请记住在退出前重置颜色(curses.wrapper 应该为您做这件事)。
def func(stdscr):
if curses.can_change_color():
# init_color(n, r, g, b)
# n=0 is background
curses.init_color(0, 0, 0, 0)
c = stdscr.getkey()
关于Python:诅咒和默认的黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514137/