- Install windows-curses package
- Test out curses
- Curses tutorial
- Reference links
This post only discusses how to get curses working in Windows. A full curses tutorial is also available.. For a tutorial on how to use curses, check out Curses Programming in Python.
The curses package is part of the Python standard library and is useful for creating text-based user interfaces and generally controlling the screen and keyboard input. The big problem is that it doesn't work out-of-the-box on Windows. This show you how to get curses working in Windows. This was tested in Windows 10 with Python 3.6. This gets the screen control, keyboard input, and colors all working. It uses the windows-curses package.
The curses library goes back decades and is used to control terminal/shell output. Read more about the history on the Wikipedia curses page. This is not a full tutorial on curses programming. Refer to the official documentation, Curses Programming with Python. That will teach you how to actually use the library.
You might also be interested in the tutorial Colorize Terminal Output in Python.
In Windows 10, some color escape codes are supported without any special configuration. Read more at MSDN Console Virtual Terminal Sequences. It is not full curses support but some colors and cursor control abilities work.
Install windows-curses package
You can use pip to install the windows-curses package. That's really all there is to it! This package will make it so you can use the Python standard curses module in Windows. From your command prompt or shell, run pip install or preferably python -m pip install like this:
python -m pip install windows-curses
Test out curses
After installing the windows-curses package using pip, you can test it out with code:
# Clear the screen and hold it for 3 seconds
screen = curses.initscr()
For a tutorial on how to use curses, check out Curses Programming in Python.
After reading this, you should know how to get curses applications running in Windows. To learn more about how to use curses in your applications, refer to Curses Programming with Python (official documentation). You might also be interested in the tutorial Colorize Terminal Output in Python.