Hi,
I'm new to the forums and just found this subsection.
Basically, I just started reading a book about Python, and the language is great and all that.
My question is: How do I change the colour of the output text?
I already tried with the MS-DOS command:
import os
os.system("color 17")
But that changes the colour of the whole text and the whole background.
Is there a way (Say, manipulating ANSI escape codes) to change the background and text colour of the output text?
I know the function is OS-specific but still.
Thanks in advance.
EDIT: Also, if anyone knows how to do this in C, I would really appreciate it.
[url=http://docs.python.org/library/curses.html]Curses[/url] could probably do color output.
In C (Windows):
[cpp]
#include <windows.h>
#include <stdio.h>
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSIFY);
puts("This line is coloured!\n");
return 0;
}
[/cpp]
For more info on the attributes:
[url]http://msdn.microsoft.com/en-us/library/ms682088(VS.85).aspx#_win32_character_attributes[/url]
You can easily wrap the above into a single function for setting the console color.
For POSIX, you should rely on the markup format for your terminal, they usually support console colouring which you can easily use by using escape characters in your strings.
I'll try that, PDCurses for Windows is half-dead.
(pity, though, I'd rather gotten used to bunging applications into Xcode just fine)
Thanks people.
You were more helpful than the guys in the Python Forums :P
And everyone says facepunch is mean. :frown:
Sorry, you need to Log In to post a reply to this thread.