Question

Hello all I am working with ncurses (my first time working with a cli) and I keep getting this error

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

Here is my code:

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()

It has more errors when I take start_color() out can anyone please advise as to a better course of action? Thanks!!!!

Was it helpful?

Solution

Check manual on curses and be sure to call right methods on right objects.

curses.initscr() Initialize the library. Return a WindowObject which represents the whole screen.

So, curses.initscr() returns WindowObject but start_color() is in curses module itself. You ought to init colors this way

curses.start_color()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top