Skip to main content
 首页 » 编程设计

python curses 文本框小部件

2025年05月04日19thcjp

#! /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 programming page .