首先让我以我刚刚学习这个库并试图让它工作并将在以后的迭代中清理它作为序言。
那就是说我的代码抛出了这个错误:
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()