如何在python curses中使用或不使用任何输入字符串来转义子窗口?

时间:2017-01-09 07:59:24

标签: python curses python-curses

在python curses中,如果我使用scr.subwin()绘制一个子窗口来获取带有getstr()函数的输入,如下所示

search_box = screen.subwin(3, 30, 20, 30)
search_box.clear()
search_box.box()
search_box.addstr(1, 1, "GoTo:")
search_box.refresh()
curses.echo()
new_x = int(search_box.getstr(1, 6, 20))
search_box.clear()

我决定不提供任何意见。如何逃离新的子窗口?

由于

1 个答案:

答案 0 :(得分:0)

我已解决了我的问题,如下所示

search_box = screen.subwin(3, 30, 20, 30)
search_box.clear()
search_box.box()
in_str = "GoTo:"
val_str = ""
search_box.addstr(1, 1, in_str)
search_box.refresh()
curses.echo()
char = search_box.getch()
try:
    int(chr(char))
    val_str += chr(char)
except:
    pass

while  char != 27: # Escape Key Value
    if char == 10: # Enter Key Value
        new_x = int(val_str)
        break
    else:
        search_box.clear()
        search_box.box()
        search_box.addstr(1, 1, in_str+val_str)
        search_box.refresh()
        char = search_box.getch()
        try:
            int(chr(char))
            val_str += chr(char)
        except:
            if char == 127:
                if len(val_str) > 0:
                    val_str = val_str[:-1]