2017-01-09 51 views
-1

在蟒蛇詛咒,如果我使用scr.subwin畫一個子窗口(),以獲得與getstr()函數的輸入如下如何在python curses中使用或不使用任何輸入字符串來轉義子窗口?

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() 

,我決定不提供任何輸入。我怎樣才能逃脫新的子窗口?

感謝

回答

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] 
相關問題