Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit text using Python and curses Textbox widget?

Tags:

python

ncurses

Has anybody got a working example of using the curses.textpad.Textbox widget to edit existing text? This is, of course, in a Linux terminal (e.g. xterm).

like image 805
Keith Avatar asked Jan 03 '11 01:01

Keith


People also ask

What is Stdscr in Python?

The stdscr object returned by the initscr() function is a window object that covers the entire screen. Many programs may need only this single window, but you might wish to divide the screen into smaller windows, in order to redraw or clear them separately.

How do you get input on curses?

The curses library itself offers only very simple input mechanisms. Python's support adds a text-input widget that makes up some of the lack. The most common way to get input to a window is to use its getch() method. getch() pauses and waits for the user to hit a key, displaying it if echo() has been called earlier.

Does curses come with Python?

The curses package comes with the Python standard library. In Linux and Mac, the curses dependencies should already be installed so there is no extra steps needed. On Windows, you need to install one special Python package, windows-curses available on PyPI to add support.


1 Answers

textpad.Textbox(win, insert_mode=True) provides basic insert support. Backspace needs to be added though.

like image 53
Rift Angel Avatar answered Sep 21 '22 04:09

Rift Angel