Windows Curses Support
The `windows-curses` library provides a compatible implementation of the standard Python `curses` module for Microsoft Windows environments. It enables the creation of text-based user interfaces (TUIs) on Windows, bridging the gap as the native `curses` module is Unix-only. Currently at version 2.4.2, it sees active development with regular updates for new Python versions.
Common errors
-
ModuleNotFoundError: No module named '_curses'
cause The Python `curses` module is not available by default on Windows. Although `windows-curses` provides it, the package might not be installed or the Python environment is misconfigured.fixEnsure `windows-curses` is installed in your active Python environment: `pip install windows-curses`. If using a virtual environment, activate it first. -
AttributeError: 'module' object has no attribute 'initscr' (most likely due to a circular import)
cause Your Python script is likely named `curses.py`, which conflicts with the imported `curses` module, causing Python to import your local file instead of the actual library.fixRename your Python script file to something other than `curses.py` (e.g., `my_app.py`). -
AttributeError: module 'curses' has no attribute 'LINES'
cause The `curses.LINES` (or `curses.COLS`) attribute is only populated after the curses environment has been initialized, typically by calling `curses.initscr()` or `curses.wrapper()`.fixAccess `curses.LINES` and `curses.COLS` only after `curses.initscr()` has been called. If using `curses.wrapper`, ensure the access happens inside the function passed to `wrapper`. -
Program runs but immediately exits or does nothing (Python 3.12)
cause Specific compatibility issues with `windows-curses` and Python 3.12 cause applications to fail silently.fixDowngrade your Python installation to version 3.11, or check for a new `windows-curses` release that explicitly lists Python 3.12 support. (Python 3.13 and 3.14 are supported by recent versions).
Warnings
- breaking The `windows-curses` package has known compatibility issues with Python 3.12, where it may install but programs using it will silently exit or do nothing.
- gotcha Naming your Python script `curses.py` will cause a circular import, leading to `AttributeError` when trying to call `curses.initscr()` or other curses functions.
- gotcha Attributes like `curses.LINES` and `curses.COLS` are only defined after `curses.initscr()` (or `curses.wrapper`) has been called. Attempting to access them before initialization will result in an `AttributeError`.
- gotcha Curses applications, even with `windows-curses`, may not function correctly or display properly when run within integrated terminals of IDEs like VS Code or PyCharm, but often work fine in a standalone Windows Command Prompt or PowerShell.
- gotcha For `windows-curses` versions prior to 2.0, automatic terminal resizing (similar to `SIGWINCH` on Unix-like systems) for applications developed against ncurses might not work out-of-the-box.
Install
-
pip install windows-curses
Imports
- curses
import _curses
import curses
- wrapper
from curses import wrapper
Quickstart
import curses
from curses import wrapper
def main(stdscr):
# Clear screen
stdscr.clear()
# Display a simple message
stdscr.addstr(0, 0, "Hello from windows-curses!")
stdscr.addstr(1, 0, "Press any key to exit.")
# Refresh the screen to show changes
stdscr.refresh()
# Wait for user input
stdscr.getch()
if __name__ == '__main__':
wrapper(main)