Question

I'm writing a small sudoku game/solver in Linux using python with TUI (not GUI, that's just lame) just for fun. My question is, which lib is better (by that I mean easier to handle, better support, more straight-forward and understandable), the choices are curses or urwid or if anyone have better suggention, and why? I have some Tkinter and wxPython experiences.

Any help or information will be appreciated.

Was it helpful?

Solution

You might want to check out Unicurses, which wraps the python core curses module in UNIX systems and wraps the free pdcurses library on windows-based machines.

This library is designed to emulate the syntax and style of the original ncurses library, so if you're interested in learning TUI design using curses-style programming, then check it out.

Urwid is, from what little documentation I've read, a very interesting library which uses event loops (the reactor pattern) as a basis for application design, much like tkinter or Twisted. Also, urwid has an event loop class specifically designed for use with Twisted, so if your aim is to created TUIs for use over networks, its a good choice. Twisted also uses the reactor pattern, so if you want to learn that style, I'd recommend it.

Finally, if you do go with an ncurses-style library, check out Dan Gookin's book on ncurses. A very good resource, and the only one I know of which is in print today.

There are other options such as newt, pygcurses, and so on, but this should get you started. Best of luck, TUI programming today is one of those technological fetishes that can be hard to break into, but it's rewarding.

OTHER TIPS

While the above is a perfectly reasonable solution for Linux, The OP asked for other suggestions and a justification for them.

Who wants to use a low level API like curses in a modern OO language like Python? Let alone if you are stuck inside Windows (which the OP isn't, but is a problem for a lot of people out there)... There must be a better way.

To try to resolve this, I have put together a simple cross platform class (yup - Windows is included without falling back to PDcurses) to do all the things most people want from their terminal/console. 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. You can find the Screen class in https://github.com/peterbrittain/asciimatics.

In addition, I've created a load of highr level objects to create animations and TUIs. For example, this is a recording of a sample using the TUI widgets:

Text UI widgets

If there's an extra feature you need, let me know and I'll see what I can do.

If your game will run inside a console, then just pick curses.

If your game will run as a GUI application, then just pick PySide.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top