#! /usr/bin/python
import curses
import curses.textpad as textpad
try:
mainwindow = curses.initscr()
textpad.Textbox(mainwindow).edit()
finally:
curses.endwin()
问题是我输入了一个字符,但屏幕上显示了两个字符。
答案 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)
import curses
import curses.textpad as textpad
try:
mainwindow = curses.initscr()
curses.noecho()
textpad.Textbox(mainwindow).edit()
finally:
curses.endwin()