简体   繁体   English

如何在 python 诅咒中有或没有任何输入字符串的情况下转义子窗口?

[英]How can I escape sub-window with or without any input string in python curses?

In python curses, if I draw a sub-window using scr.subwin() to get input with getstr() function as below在 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()

and I decide not provide any input.我决定不提供任何意见。 How can I escape new sub-window?我怎样才能逃脱新的子窗口?

Thanks谢谢

I have resolved my problem as following我已经解决了我的问题如下

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM