Cold Diamondz Cold Diamondz - 6 months ago 80
Python Question

Input in a Python text-based GUI (TUI)

I have been trying to make my own UI that is text-based in python 2.7, but I thought of an idea about input. So I figured something like this:

input = raw_input("|" + "input: ".center(78) + "|")
, but of coarse, the cursor is way far on the right (just realized it wouldn't work before i even typed it in :P). So, the question is, is how do I put an input in the middle of the screen with text on the same line (on both sides) and have the cursor type after I write "Input: "? And if your wondering, im using this:

if True:
print c + "Hi! This is a text-based GUI!".center(78, h) + c
print c + "-" * 78 + c
print v + "OPTIONS".center(78) + v
print c + "-" * 78 + c
print v + "1 - Quit".center(78) + v
for i in range(1, 7):
print v + " " * 78 + v
print c + "-" * 78 + c


in the interpreter and it looks decent:

+------------------------Hi! This is a text-based GUI!-------------------------+
+------------------------------------------------------------------------------+
| OPTIONS |
+------------------------------------------------------------------------------+
| 1 - Quit |
| |
| |
| |
| |
| |
| |
+------------------------------------------------------------------------------+


Note: I use Windows XP

Answer

Also try useful built atop curses high level framework urwid. With that thing you could do rich and colorful interfaces. Buttons, edit fields, even status bars and progress bars and all that you need. To start working you only need Python curses installed and urwid folder with its sources (you can transfer whole urwid library with your application as standalone bundle!). It works even under cygwin under Windows XP/7 where is, as we know, no curses ports for Python.

urwid portfolio

No more lowlevel, sometimes very boring curses :)