Urwid for Python, a ncurses library

November 19, 2011

This, is the first part of a six posts series on Urwid.

I really like ncurses programs, it’s certainly what I use the most for an every day usage. The curses module from Python provides some elements to build an application, it’s what I used for my last program Tyrs. Unfortunately, the module doesn’t provide any widgets or advances elements, usually instead of reinvents the wheel, we use a library. As far as I know, Python have only two libraries for ncurses.

Unfortunately, their isn’t any others libraries that those two.

It’s always interesting when starting consider a library to know if their are others programs using it too, a list is provide by the website, with some interesting programs, such as wicd-curses, hachoir and the Debian “reportbug” tool.

The most interesting pieces of example to get start with come from this page, a set of small programs with screenshot.

Urwid come with lots of features and widget, allow you to display a nice layout easily, editing text, 256 colors, utf-8, check box, advance list management, mouse event and much more. The documentation and tutorial is well documented.

Urwid is maybe not so easy to get start with if you’re not used to play with library, and maybe it’s why it isn’t more popular but have lots of potential. Urwid has became mature, and after seven years of development as reach the 1.0.0 release few months ago.

Here is a traditional Hello World, with a quit keystroke handling.

import urwid

txt = urwid.Text("Hello World")
fill = urwid.Filler(txt, 'top')

def exit(input):
    if input in ('q', 'Q'):
        raise urwid.ExitMainLoop()

loop = urwid.MainLoop(fill, unhandled_input=exit)

I will soon write some more posts about Urwid, with codes and more technical. This is only a short introduction of Urwid. I hope this post will give you enough reason to give Urwid a try.


Related-ish Posts


I'm Nicolas Paris, aka Nic0, I like to share about programming and Linux tricks. Follow me on Twitter, where the content is pretty much like here, mainly programming stuff. Or visite my website