Python curses Module
Example
Check if curses can be imported on this platform:
try:
import curses
print(True)
except Exception:
print(False)
Try it Yourself »
Definition and Usage
The curses module provides terminal handling for character-cell displays, supporting text UIs.
It may not be available on all platforms (notably some Windows environments).
Note: Availability is platform-dependent; the example above prints whether import succeeds.
Members
Member | Description |
---|---|
ACS_* | Box-drawing character constants (e.g., ACS_HLINE , ACS_VLINE ). |
addch() | Window method: Add a character at the current cursor position. |
addstr() | Window method: Add a string at the current cursor position. |
border() | Window method: Draw a border around the window. |
box() | Window method: Draw a box using default border characters. |
cbreak() | Enter cbreak mode (disable line buffering). |
clear() | Window method: Clear the window. |
COLOR_* | Color constants (e.g., COLOR_RED , COLOR_BLUE ). |
color_pair() | Return the attribute value for a color pair number. |
curs_set() | Set cursor visibility (0=hidden, 1=normal, 2=highly visible). |
derwin() | Create a derived window (relative to its parent). |
echo() | Enable echoing of input characters. |
endwin() | Deinitialize the library and return terminal to normal status. |
getch() | Window method: Read a character from the window. |
getkey() | Window method: Read a key as a string (translates special keys). |
getmaxyx() | Window method: Return (nlines, ncols) of the window. |
halfdelay() | Set half-delay mode (tenths of seconds). |
has_colors() | Return True if the terminal supports color. |
init_pair() | Define a color pair (foreground/background). |
initscr() | Initialize the library and return a window object representing the entire screen. |
keypad() | Window method: Enable or disable keypad mode (function/arrow keys). |
KEY_* | Constants for special keys (e.g., KEY_UP , KEY_F1 ). |
move() | Window method: Move the cursor to (y, x). |
napms() | Sleep for the specified number of milliseconds. |
newwin() | Create a new window. |
nodelay() | Window method: Set/get nodelay mode (non-blocking reads). |
nocbreak() | Leave cbreak mode. |
noecho() | Turn off automatic echoing of keys to the screen. |
noraw() | Leave raw mode. |
raw() | Enter raw mode (disable line processing). |
refresh() | Window method: Update the physical screen. |
start_color() | Initialize color functionality. |
timeout() | Window method: Set blocking read delay in milliseconds. |
use_default_colors() | Allow use of terminal’s default colors. |
wrapper() | Perform proper initialization and cleanup around a curses main function. |