Changing IDLE's stdout color at runtime

Ben Hutchings ben.hutchings at
Mon Dec 18 15:08:34 CET 2000

anton at (Anton Vredegoor) writes:

> Hello,
> I am looking for something like:
> def SetIdleStdoutColor(color):
> 	pass  # this function needs defining
> print 'hello world'
> SetIdleStdoutColor('green') 
> print 'hello again'
> SetIdleStdoutColor('defaultcolor')
> Has anybody got an idea how to do this?

You'd need to work out whether standard output is connected to a
terminal or terminal emulation; if so, what kind of terminal that is;
whether that terminal supports colour; and if so, what the appropriate
control codes are for changing the colour.  You *could* assume that
any terminal supports the ANSI escape codes for colour (ESC [30n, ESC
[31n, etc, if I remember correctly), but that would really annoy
anyone using a terminal that doesn't.

Any opinions expressed are my own and not necessarily those of Roundpoint.

More information about the Python-list mailing list