Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python诅咒不';t似乎不能与超过256对颜色搭配_Python_Python 3.x_Ncurses_Python Curses - Fatal编程技术网

Python诅咒不';t似乎不能与超过256对颜色搭配

Python诅咒不';t似乎不能与超过256对颜色搭配,python,python-3.x,ncurses,python-curses,Python,Python 3.x,Ncurses,Python Curses,我想在我的应用程序中使用256色背景和256色前景,使用curses。这需要65536对颜色:这似乎得到了支持诅咒。颜色对报告65536。这是我的代码: def干管(stdscr): 诅咒。使用默认颜色() 对于范围内的i(0,curses.COLORS): 对于范围(0,curses.COLORS-1)中的j:#有点像黑客,但无论如何都应该可以工作。 curses.init_pair(i*curses.COLORS+j+1,i,j)#颜色1是硬连线的,所以我们必须省略一种颜色 ... srds

我想在我的应用程序中使用256色背景和256色前景,使用
curses
。这需要65536对颜色:这似乎得到了支持<代码>诅咒。颜色对报告65536。这是我的代码:

def干管(stdscr): 诅咒。使用默认颜色() 对于范围内的i(0,curses.COLORS): 对于范围(0,curses.COLORS-1)中的j:#有点像黑客,但无论如何都应该可以工作。 curses.init_pair(i*curses.COLORS+j+1,i,j)#颜色1是硬连线的,所以我们必须省略一种颜色 ... srdscr.addstr(y,x,char,curses.color_对(fg*curses.COLORS+bg))#错误 诅咒可能允许我定义65535(因为0是硬连线的)颜色对,但不允许我使用它们。发生什么事?如何使用超过256对颜色

下面是确切的错误消息,变量名称当然不同

Traceback (most recent call last):
  File "client.py", line 173, in <module>
    a.mainLoop()
  File "client.py", line 134, in mainLoop
    curses.wrapper(self.main)
  File "/usr/local/lib/python3.10/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "client.py", line 169, in main
    self.drawScreen()
  File "client.py", line 152, in drawScreen
    win.draw()
  File "client.py", line 121, in draw
    self.s.addstr(y, x, char[2], curses.color_pair(char[0] * 256 + char[1]))
ValueError: Color number is greater than COLORS (256).

回溯(最近一次呼叫最后一次):
文件“client.py”,第173行,在
a、 mainLoop()
mainLoop中第134行的文件“client.py”
curses.wrapper(self.main)
文件“/usr/local/lib/python3.10/curses/_init__.py”,第94行,在包装器中
返回函数(stdscr,*args,**kwds)
文件“client.py”,第169行,在main中
self.drawScreen()
drawScreen中第152行的文件“client.py”
赢。抽签
文件“client.py”,第121行,在绘图中
self.s.addstr(y,x,char[2],curses.color_对(char[0]*256+char[1]))
ValueError:颜色编号大于颜色(256)。

我在Linux上使用Python3.10,我尝试过3.9、3.8.5等,但没有任何效果。

也许这一行:
用于范围内的I(0,curses.COLORS):
,因为您在init\u pair调用中使用了
I
的完整范围。@ThomasDickey有什么问题吗?这部分“curses.COLOR\u PAIRS报告65536”这是因为python curses使用的是ncurses ABI 5(如果它使用的是ABI 6,它将很容易得到扩展的数字——例如,它的绑定中不应该有任何代码强制颜色为16位短值)。@ThomasDickey等等,我很困惑:我没有
ncurses
ncurses 6.x总是可以为ABI 5编译(大多数打包程序已经开始使用ABI6,但不是全部)。此外,限制可能在python绑定中(我没有研究过…)。