Printing text to row and column coordinates in Python?

Go To StackoverFlow.com

3

I haven't found anything about this, but maybe that's because it isn't possible. But is there a way to print text to coordinates in Python? For example, if I wanted to print the string 'A' at the 3rd row and 5th column of the command window, how could I do that? I found ways to get around it and print two different strings at different coordinates using \n for rows and repeating spaces for columns, but it's just too tedious to write the code.

2012-04-04 22:42
by Wall_Dough
I think you can create a function, and then print it with that number of spaces in front, between, and after? I am not sure if that's what you asking for. def printCorrdinate(myString, x, y):George 2012-04-04 22:45
@George I'm asking if there is a function that has as arguments the x and y coordinates that you wish to print the text to. See Output() in TI-BASIC: http://tibasicdev.wikidot.com/outpu - Wall_Dough 2012-04-04 22:48
Maybe check out this http://docs.python.org/howto/curses.html#windows-and-pad - George 2012-04-04 22:50


1

This is possible. The curses library comes standard and is documented here. There are probably others but that will do what you're looking for. In particular, curses.getsyx() might be what you need.

2012-04-04 22:46
by GrantVS
I have Windows 7... Not Unix. Curses doesn't seem to be installed with my build (Python 2.7.2), or at least not working properly - Wall_Dough 2012-04-04 22:58
Hi. I see. Try Console found at http://effbot.org/downloads . I haven't used it much, but it could help. The documentation at http://www.effbot.org/zone/console-handbook.htm seems to indicate it can do what you're looking for - GrantVS 2012-04-04 23:16
There is no Console for 2.7... Most up-to-date version is 2. - Wall_Dough 2012-04-04 23:24
PyGame MIGHT do what I want it to. I've had that installed since Monday but haven't done anything with it - Wall_Dough 2012-04-05 18:39


1

If you want to avoid the curses module, you can get right down to the basics by using ANSI escape sequences. A quick explanation of the relevant cursor-moving codes can be found here. These work right out of the box on Linux/Unix, for Windows you'll need the coloroma package.

For a cute, cross-platform example using this technique for animation, see here.

2015-01-03 20:11
by Cheyne H
Ads