简体   繁体   English

python curses文本框小部件

[英]python curses textbox widget

#! /usr/bin/python

import curses
import curses.textpad as textpad

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

the problem is that I type one character,but two characters display on screen. 问题是我键入了一个字符,但屏幕上却显示了两个字符。

Echoing is on by default. 默认情况下,回显处于打开状态。 You need to call noecho for deactivating it. 您需要致电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()

(the script has been tested on Python 2.7). (该脚本已在Python 2.7上进行了测试)。 I suggest you to have a look to the curses programming page . 我建议您看一下curses编程页面

Use curses.noecho() : 使用curses.noecho()

import curses
import curses.textpad as textpad

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM