curses中的多个Textbox

时间:2013-10-22 09:21:38

标签: python linux curses

当我按 Enter

时,我需要在curses中创建两个Textbox并在它们之间切换

当我按下第二个文本框的Enter键时,此代码将光标放在屏幕的左上角,我无法阻止它。

import curses
import curses.textpad as textpad

def main(screen):
    """screen is a curses screen passed from the wrapper"""

    while True:
        event = screen.getch() 
        if event :
            textpad.Textbox(curses.newwin(1,13,4,0), insert_mode=True).edit()
            textpad.Textbox(curses.newwin(1,13,4,16), insert_mode=True).edit()
            screen.refresh()      

if __name__ == '__main__':     
    curses.wrapper(main) 

1 个答案:

答案 0 :(得分:1)

看起来您甚至不需要致电getch(),因为这已经足够了:

import curses
import curses.textpad as textpad

def main(screen):
    """screen is a curses screen passed from the wrapper"""
    while True:
        textpad.Textbox(curses.newwin(1,13,4,0), insert_mode=True).edit()
        textpad.Textbox(curses.newwin(1,13,4,16), insert_mode=True).edit()

if __name__ == '__main__':   
    curses.wrapper(main)