9

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.

4

3 に答える 3

10

UNIXシステムでpythonコアcursesモジュールをラップし、Windowsベースのマシンで無料のpdcursesライブラリをラップするUnicursesを確認することをお勧めします。

このライブラリは、元のncursesライブラリの構文とスタイルをエミュレートするように設計されているため、cursesスタイルのプログラミングを使用してTUIデザインを学習することに興味がある場合は、それを確認してください。

Urwidは、私が読んだ小さなドキュメントから、 tkinterやTwistedのように、アプリケーション設計の基礎としてイベントループ( reactorパターン)を使用する非常に興味深いライブラリです。また、urwidにはTwistedで使用するために特別に設計されたイベントループクラスがあるため、ネットワーク上で使用するTUIを作成することが目的の場合は、これを選択することをお勧めします。Twistedもreactorパターンを使用しているので、そのスタイルを学びたいのであれば、それをお勧めします。

最後に、ncursesスタイルのライブラリを使用する場合は、DanGookinのncursesに関する本を確認してください。非常に優れたリソースであり、私が知っている唯一のリソースが今日印刷されています。

newtpygcursesなどの他のオプションもありますが、これで始めることができます。幸運なことに、今日のTUIプログラミングは、侵入するのが難しい技術的なフェチの1つですが、やりがいがあります。

于 2012-05-10T14:11:27.380 に答える
9

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.

于 2015-06-14T22:39:53.313 に答える
1

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.

于 2012-05-08T22:26:09.693 に答える