Python TUI libs [closed]
Asked Answered
A

3

11

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.

Applicant answered 8/5, 2012 at 21:36 Comment(0)
F
11

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.

Funches answered 10/5, 2012 at 14:11 Comment(2)
Since I don't care for windose, unicurses may be unnecessary. Newt looks good, buy its name reminds me of the GOP nomination nightmare... I saw some examples of TUI games on pygcurse's site, that's more of my purpose. Thank you very much.Applicant
Well if you're hoping to get into game dev with curses, also check out libtcod, a very powerful TUI library for roguelikes and such. It's pretty much the go-to library for non-networked roguelike development in Python, and its relatively easy to use.Funches
P
10

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 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.

Phonation answered 14/6, 2015 at 22:39 Comment(1)
holy crap, this library is awesome! thanks for sharing! <3Ebullience
T
2

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.

Tirado answered 8/5, 2012 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.