Search code examples
python-3.xidecurses

python:curses freezes in IDLE


I was trying to learn about the curses.I imported the curses module and started to work in the IDE.After setting curses.initscr to the variable stdscr the IDLE suddenly freezes.I did it just like this:

>>> import curses
>>> stdscr = curses.initscr()

Then the IDE just freezed.Could anyone explain what had just happen.And how can I avoid this from happening?


Solution

  • The curses module only run on Unix with a fixed-pitch font, rows and columns, text terminal or a graphics window that emulates a text terminal. Idle executes user code in a no-terminal process and displays results in its tk graphics window Shell. The two are not compatible and I suspect the same would be true of any graphics IDE unless the IDE noticed 'import curses' and ran the program in a special mode.

    My advice is to edit your code in Idle or any other editor and then run the code at the command line of your text-mode console window. For instance

    .../mydir> python try_curses.py
    

    where mydir is the directory containing your file.