Search code examples
python-3.xpython-curses

How to add text and get input from the bottom of the terminal python curses?


I am making an app in python curses and need to add text and get input from the bottom of the terminal. How do I do this?

I have tried using the getmaxyx function than then taking away 1 from the height then taking that away from the whole height from that, for people who may be confused:

Height - (height - 1)

and using that as the height arg for addstr but it threw an error saying that it returned ERR. please help!


Solution

  • Curses position is minimal at the top of the terminal and maximal at the bottom of the terminal so the y position at the bottom is height - 1. Here is a minimal example:

    import curses
    
    def main(win):
        win.addstr(win.getmaxyx()[0] - 1, 0, 'Hello World!')
        win.refresh()
        win.getch()
    
    curses.wrapper(main)