#! /usr/bin/python
import curses
import curses.textpad as textpad
try:
mainwindow = curses.initscr()
textpad.Textbox(mainwindow).edit()
finally:
curses.endwin()
问题是我输入了一个字符,但屏幕上显示了两个字符。
回显默认开启。您需要致电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 编程页面。
import curses
import curses.textpad as textpad
try:
mainwindow = curses.initscr()
curses.noecho()
textpad.Textbox(mainwindow).edit()
finally:
curses.endwin()