python - Curses alternative for windows

ID : 131310

viewed : 9

Tags : pythoncursespython

Top 5 Answer for python - Curses alternative for windows

vote vote


I'm happy to report that there's now a Windows build of Curses available as an extension for Python on Windows, from here. (I didn't write it, and I don't know who maintains it.)

You can run the installer, and import curses to get curses running. (Verified on 64-bit Windows 7 and Windows 8.)

@ArtOfWarfare points out that you can install this via Pip with this commend:

pip install 
vote vote


The original question was whether there is an alternative to curses on Windows.

One answer is to use the Win32 console API. You can program this directly in Python using the excellent pywin32 package if you're already familiar with the console API.

However, I found this too low level for my recent project. I was also less than keen on forcing my users to build/install PDcurses, and besides, I also find curses too low level for a modern OO language like Python too.

I have therefore put together a high level cross-platform API to do all the things most people want from their terminal/console. The asciimatics package will provide most of your input and output needs. If you're on Linux this is a more human way to program curses. If you're on Windows, the same class works as is with no external binary dependencies. See below for an example screenshot:

Sample output

There are many other effects and widgets available which you can find in the gallery, but if there's an extra feature you need, let me know and I'll see what I can do.

vote vote


Then you're out of luck i'm afraid. There's no real cross-platform version or port of curses/ncurses, there is a "dialogue" port which works, but it's limited in capabilities.

Your best bet is to run CygWin or MinGW32, both are, in "loose terms", a Linux system+terminal emulator which has much of the binaries you need. They can run native Linux/Unix binaries inside the terminal and access your "host" system files at any time, so it's like patching Windows with a kick-ass terminal with all your goodies from the Linux world. You'll still need some basic knowledge of Linux and how the commands etc work, but you'll figure it out.

Screenshot of MinGW and CygWin

Here's a Pyglet GUI example:

import pyglet from import *  class main (pyglet.window.Window):     def __init__ (self):         super(main, self).__init__(800, 600, fullscreen = False)         self.button_texture = pyglet.image.load('button.png')         self.button = pyglet.sprite.Sprite(self.button_texture)          ## --- If you'd like to play sounds:         #self.sound ='music.mp3')          self.alive = 1      def on_draw(self):         self.render()      def on_close(self):         self.alive = 0      def on_mouse_press(self, x, y, button, modifiers):         if x > self.button.x and x < (self.button.x + self.button_texture.width):             if y > self.button.y and y < (self.button.y + self.button_texture.height):                 self.alive = 0      def on_key_press(self, symbol, modifiers):         if symbol == 65307: # [ESC]             self.alive = 0      def render(self):         self.clear()         self.button.draw()         self.flip()      def run(self):         while self.alive == 1:             self.render()              # -----------> This is key <----------             # This is what replaces             # but is required for the GUI to not freeze             #             event = self.dispatch_events()   x = main() 

Here's the output of that code:

enter image description here

vote vote


Here's how to install what ashes999 linked to in their answer via pip:

pip install 

This should probably be added to PyPI to make installation with pip even easier (so it could be installed by name rather than URL.)

vote vote


You may try this one. I once did the Win64-port for this (merged in there). You however need to write your Python code a bit different. This one will redirect all curses calls to the native Python version on UNIX, but call PDCURSES.DLL on Windows (download the DLL separately). It supports unicode as far as I remember:

Top 3 video Explaining python - Curses alternative for windows