Setupterm could not find terminal, in Python program using curses

前端 未结 6 1673
礼貌的吻别
礼貌的吻别 2020-11-28 13:07

I am trying to get a simple curses script to run using Python (with PyCharm 2.0).

This is my script:

import curses
stdscr = curses.initscr()
curses.n         


        
6条回答
  •  不知归路
    2020-11-28 13:52

    I found this question when searching for examples because I am also learning to use curses so I don't know much about it. I know this works though:

    import curses
    try:
        stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        while 1:
            c = stdscr.getch()
            if c == ord('p'):
                stdscr.addstr("I pressed p")
            elif c == ord('q'): break
    finally:
        curses.nocbreak(); stdscr.keypad(0); curses.echo()
        curses.endwin()
    

    I also added the try: finally: to make sure I get the terminal to it's original appearance even if something simple goes wrong inside the loop.

    You have to use the addstr to make sure the text is going to be displayed inside the window.

提交回复
热议问题