Changing IDLE's stdout color at runtime

Anton Vredegoor anton at vredegoor.doge.nl
Tue Dec 19 17:20:09 CET 2000


On 18 Dec 2000 14:08:34 +0000, Ben Hutchings
<ben.hutchings at roundpoint.com> wrote:

>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.

Thanks for pointing this out. After inspecting the sourcefiles I have
the following interpretation: Idle is not a terminal but a Tkinter
window redirecting standard output. The text is colorized later
according to a syntax scheme. There seems to be no obvious way of
having two lines of "stdout" with different colors in the same window.

Below is a script to change Idle's stdout color. This only works for
the standard Idle thats delivered with the python20 distribution. It
doesn't work with the idlefork-0.7.1 thats on sourceforge. By the way
this idlefork won't run with python20 unless one gets the new
"protocol.py" or manually edits line 331 and 364 to :

331: s.bind(('', self.port))  
364: s.connect((ip,port or Server.default_port))

#stdoutcolor.py

"""
 Example program showing how to change
 the foregroundcolor of stdout in Idle
"""

import sys
import time

OldStdoutForeground = sys.stdin.color.tagdefs['stdout']['foreground']
sys.stdin.color.tagdefs['stdout']['foreground'] = 'Orange'
sys.stdin.color.config_colors()
print sys.stdin.color.tagdefs
time.sleep(3)
sys.stdin.color.tagdefs['stdout']['foreground'] = OldStdoutForeground
sys.stdin.color.config_colors()







More information about the Python-list mailing list