首先,让我开始学习这个库,我正在尝试让它工作,并将在以后的迭代中清理它。
也就是说,我的代码抛出了这个错误:
Traceback (most recent call last):
File "cursesDemo1.py", line 30, in <module>
box3 = maketextbox(1,40, 10,20,"foo",deco="underline",textColorpair=curses.color_pair (0),decoColorpair=curses.color_pair(1))
_curses.error: must call start_color() first我不确定我需要在哪里调用start_color(),我似乎在谷歌上找不到任何这个错误的例子,也找不到修复它的方法。
我试着到处添加它,但被难住了,谁能给我一些指导,看看哪里或一个例子?
下面是我的完整代码:
import curses
import time
screen = curses.initscr()
def maketextbox(h,w,y,x,value="",deco=None,underlineChr=curses.ACS_HLINE,textColorpair=0,decoColorpair=0):
nw = curses.newwin(h,w,y,x)
txtbox = curses.textpad.Textbox(nw)
if deco=="frame":
screen.attron(decoColorpair)
curses.textpad.rectangle(screen,y-1,x-1,y+h,x+w)
screen.attroff(decoColorpair)
elif deco=="underline":
screen.hline(y+1,x,underlineChr,w,decoColorpair)
nw.addstr(0,0,value,textColorpair)
nw.attron(textColorpair)
screen.refresh()
return txtbox
try:
screen.border(0)
box1 = curses.newwin(22, 50, 3, 5)
box1.box()
box2 = curses.newwin(22, 50, 3, 65)
box2.box()
box3 = maketextbox(1,40, 10,20,"foo",deco="underline",textColorpair=curses.color_pair (0),decoColorpair=curses.color_pair(1))
textInput = box3.edit()
box1.addstr(2, 18, "Functions")
box2.addstr(2, 18, "Processes")
screen.refresh()
box1.refresh()
box2.refresh()
box3.refresh()
for i in range(19):
toWrite = "Does this move run = %d" % i
box1.addstr(8, 9, toWrite)
box1.refresh()
time.sleep(5)
box2.addstr(8, 9, textInput)
screen.getch()
finally:
curses.endwin()发布于 2013-12-02 19:09:14
在调用initscr之后立即调用start_color。
即:
if __name__ == "__main__":
screen = curses.initscr()
screen.start_color()
...
screen.endwin()Eric S. Raymond的“用ncurses编写程序”是对该库的低级屏幕管理部分的很好的一般性介绍。你不需要了解C语言就能理解它,因为库函数很大程度上以1:1的方式直接映射到它们的Python对应物:
http://invisible-island.net/ncurses/ncurses-intro.html
还有:http://tinyurl.com/lgkyggq,因为人们问的第一件事总是如何正确地实现滚动,这本书的很大一部分都涉及到了这个主题。
发布于 2018-04-22 01:49:00
在我的例子(python 2.7)中,这段代码修复了我的问题:
curses.start_color()https://stackoverflow.com/questions/19895768
复制相似问题