如何添加文本并从终端 python curses 的底部获取输入?

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

我正在 python curses 中制作一个应用程序,需要添加文本并从终端底部获取输入。我该怎么做?

我尝试使用 getmaxyx 函数,然后从高度中减去 1,然后从整个高度中减去 1,对于可能感到困惑的人:

身高-(身高-1)

并将其用作 addstr 的高度参数,但它抛出了一个错误,指出它返回了 ERR。请帮助!

Curses 位置在终端顶部最小,在终端底部最大,因此底部的 y 位置为 height - 1。 这是一个最小的例子:

import curses

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

curses.wrapper(main)