1

How can I write a console form looking like the one seen on the screenshot using python. This means that I can write something like

print(x=6, y=2, "z/VM ONLINE")

This code should place the text almost in the upper left corner as seen on the screenshot. Importantly the output text should never make all the other text scroll. It is also important that I can place the cursor at any coordinate and that the user is able to input text at that place.

EDIT: I need something that works under Windows.

enter image description here

David
  • 4,786
  • 11
  • 52
  • 80
  • You could have fun writing some Python bindings for [this](http://www.projectpluto.com/win32a.htm) as suggested [here](http://stackoverflow.com/questions/138153/ncurses-in-windows). – redShadow Mar 02 '11 at 13:49

2 Answers2

4

The Python curses module is made for this purpose.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
  • I have edited my question, as I need this for Windows. I am currently researching whether any version of curses will work for Windows. – David Mar 02 '11 at 13:33
  • 1
    There are some very old version of curses for windows, but no, not really. That said, you could install cygwin, and use rxvt (which can be installed in cygwin). You would likely have to use cygwin's python, however. – Arafangion Mar 02 '11 at 13:34
  • I don't know of any Windows port of curses. Maybe try using [ANSI escape sequences](http://en.wikipedia.org/wiki/ANSI_escape_code) directly. – Sven Marnach Mar 02 '11 at 13:37
  • I found this library, which seems to help: http://effbot.org/zone/console-index.htm – David Mar 02 '11 at 13:41
  • 3
    Just beware that the windows console is as slow as all heck. (I would've used stronger language than that, but I suspect that would attract the moderators) – Arafangion Mar 02 '11 at 14:00
  • I know that I am not exactly creating the Rolls Royce of applications using this interface. – David Mar 02 '11 at 15:17
2

You need to learn (in great depth) the precise capabilities of the terminal you wish to use. Specific bytes will cause the character to move left, right, up and down - or maybe not, depending on the capabilities of the terminal emulator you are using.

If you can't move the character, you'll have to keep in mind just how wide and tall the window is, and print out a "screen".

That is, to write 'z/VM Online' in the top left corner, you can just do so - and then output enough lines so that is now at the top of the screen.

Or you can just use an ncurses library.

Arafangion
  • 11,517
  • 1
  • 40
  • 72