Search code examples
pythoncurses

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.


Solution

  • Echoing is on by default. You need to call noecho for deactivating it.

    #!/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). I suggest you to have a look to the curses programming page.