

So let's begin.įirst we will use addstr() function of the stdscr object to add a custom string at a predefined position. We will start with a simple example in which we will just print in the middle of the terminal window.
#Python 3 install curses how to#
Now that you know how to write skeleton of a curses program, we will now see how to write the main() function of a curses program. The skeleton of your curses program will look something like this now, import curses The wrapper() function will handle creation and deletion of this object so you don't have to worry about that and you need to directly use it in your main function. You will be using this object to interact with your screen. This window object will represent the entire screen. You need to pass a window object to your main function as an argument. This wrapper function will do all the necessary initializations at the beginning and deinitialization at the end of your program so that you won't have to do them manually. Then you need to pass this main function of yours as an argument to the wrapper function of curses module.

You could name this function anything but typically it is named as main so we will follow it here also. import cursesĪfter this you need to create a function named main() in which you will write your main code. In order to use curses in your python script you would have to import it like the turtle module. Install it using the following command, pip install windows-curses On Windows you would have to install windows-curses which adds support for the standard curses library on Windows. If you are on windows then you need to install curses using pip.

There is no need to install it explicitly. If you are on a UNIX system (Linux or MacOS) then curses comes pre-installed with python. Curses in Python Installing curses UNIX (Linux & MacOS)
