python curses文本框小部件

时间:2012-09-16 06:02:39

标签: python curses

#! /usr/bin/python

import curses
import curses.textpad as textpad

try:
    mainwindow = curses.initscr()
    textpad.Textbox(mainwindow).edit()
finally:
    curses.endwin()
问题是我输入了一个字符,但屏幕上显示了两个字符。

2 个答案:

答案 0 :(得分:4)

默认情况下启用回声。您需要致电noecho停用它。

#!/usr/bin/env python

import curses
import curses.textpad as textpad

try:
    mainwindow = curses.initscr()
    # Some curses-friendly terminal settings
    curses.cbreak(); mainwindow.keypad(1); curses.noecho()
    textpad.Textbox(mainwindow).edit()
finally:
    # Reverse curses-friendly terminal settings
    curses.nocbreak(); mainwindow.keypad(0); curses.echo()
    curses.endwin()

(该脚本已在Python 2.7上测试过)。我建议你看一下curses programming page

答案 1 :(得分:2)

使用curses.noecho()

import curses
import curses.textpad as textpad

try:
    mainwindow = curses.initscr()
    curses.noecho()
    textpad.Textbox(mainwindow).edit()
finally:
    curses.endwin()