Ncurses start.color() issue



大家好,我正在使用ncurses(我第一次使用cli),我一直收到这个错误

Traceback (most recent call last):
    File "cursesDemo1.py", line 5, in <module>
    screen.start_color()
AttributeError: start_color

这是我的代码:

import curses 
import time
screen = curses.initscr()
screen.start_color()
    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()

当我取出start_color()时,它有更多的错误。有人能建议我采取更好的行动吗?谢谢

查看curses的手册,并确保在正确的对象上调用正确的方法。

curses.initscr()初始化库。返回一个WindowObject表示整个屏幕。

因此,curses.initscr()返回WindowObject,但start_color()本身在curses模块中。你应该以这种方式初始化颜色

curses.start_color()

最新更新