473,578 Members | 3,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python/IDLE - text in different colours

To make life easier for my users, I'd like to colour my prompt string (as
handed to raw_input()) a different colour to that produced by print. I'm
using Python 2.4.1 and IDLE 1.1.1 on Windows XP. Is it possible, and if so,
how?
tia,
Bill
Jul 19 '05 #1
4 8212


Bill.

The way is the click on view, then click script checker, or something like
that. It will color code the text for you.

Nathan
"Bill Davy" <Bi**@SynectixL td.com> wrote in message
news:d9******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...
To make life easier for my users, I'd like to colour my prompt string (as handed to raw_input()) a different colour to that produced by print. I'm using Python 2.4.1 and IDLE 1.1.1 on Windows XP. Is it possible, and if so, how?
tia,
Bill


--
----------------------------------------------------------------
Posted via UsenetRevolutio n.com - Revolutionary Usenet
** HIGH RETENTION ** Specializing in Large Binaries Downloads **
http://www.UsenetRevolution.com
Jul 19 '05 #2
Thank you Nathan, but that does not quite address my question. I want to
have code in Python so

make_the_prompt _string(Red)
make_print_outp ut(Green)
while True:
s = raw_input("This prompt (which is really several lines long) will be
in red: ")
Foo(s)
print "And the result is in Green so the user can see it"

"Nathan Pinno" <fa********@hot mail.com> wrote in message
news:42******** **************@ news.usenetrevo lution.com...


Bill.

The way is the click on view, then click script checker, or something
like
that. It will color code the text for you.

Nathan
"Bill Davy" <Bi**@SynectixL td.com> wrote in message
news:d9******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...
> To make life easier for my users, I'd like to colour my prompt string

(as
> handed to raw_input()) a different colour to that produced by print.

I'm
> using Python 2.4.1 and IDLE 1.1.1 on Windows XP. Is it possible, and

if
so,
> how?
> tia,
> Bill
>
>


--
----------------------------------------------------------------
Posted via UsenetRevolutio n.com - Revolutionary Usenet
** HIGH RETENTION ** Specializing in Large Binaries Downloads **
http://www.UsenetRevolution.com

Jul 19 '05 #3
"Bill Davy" <Bi**@SynectixL td.com> wrote in
news:d9******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com:
To make life easier for my users, I'd like to colour my prompt string
(as handed to raw_input()) a different colour to that produced by
print. I'm using Python 2.4.1 and IDLE 1.1.1 on Windows XP. Is it
possible, and if so, how?
tia,
Bill


Communicating with a Program

Say we want the shell to distinguish more clearly, the output of external
programs from the input prompt, the commands, and the shell feedback. We
want the output of external programs to be indented and displayed in a
different colour than the other text.

Setting the colour of the text is fairly easy using ANSI terminal escape
sequences. For instance, to set the text colour to dark red, write "<Esc>
[31;2m" to the terminal (where <Esc> is the escape code — in emacs use
"C-q ESC" to write <Esc>). We can reset the output colour using "<Esc>
0m".

Printing the output of external programs in dark red, we can do using the
execute() function:

def runCommand(comm and):
print 'Running:', command

# set output colour:
sys.stdout.writ e("<Esc>[31;2m") ; sys.stdout.flus h()

os.system(comma nd)

# reset output colour
sys.stdout.writ e("<Esc>[0m")

(Here we need to flush the stdout file to make sure that the escape code
is written to the terminal before the output of the program)

http://www.daimi.au.dk/~mailund/scri...notes/process-
management.html

Jul 19 '05 #4
OK, I (sort of) tried that. Used chr() to avoid issues of which editor and
rant the following:

import sys

ESC = chr(27)
DarkRed = ESC + "[31;2m"
ResetColour = ESC + "[0m"

print "Initial colour"

sys.stdout.writ e(DarkRed) ; sys.stdout.flus h()

print "Is this dark red?"

sys.stdout.writ e(ResetColour) ; sys.stdout.flus h()

print "Final colour"

The output (in blue, using IDLE) was:

Initial colour
Is this dark red?
Final colour

So, have I missed soemthing? By the way, in the output there is a little
square box before the [ in the last two lines. Does the window Idle sets up
emulate VT100?

Hey ho, but many thanks. My user will just have to strain his eyes.
Bill

PS Thanks for the URL. Interesting.
"TouTaTis" <to******@xsFOU Rall.nl> wrote in message
news:Xn******** *************** **********@194. 109.133.242...
"Bill Davy" <Bi**@SynectixL td.com> wrote in
news:d9******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com:
To make life easier for my users, I'd like to colour my prompt string
(as handed to raw_input()) a different colour to that produced by
print. I'm using Python 2.4.1 and IDLE 1.1.1 on Windows XP. Is it
possible, and if so, how?
tia,
Bill


Communicating with a Program

Say we want the shell to distinguish more clearly, the output of external
programs from the input prompt, the commands, and the shell feedback. We
want the output of external programs to be indented and displayed in a
different colour than the other text.

Setting the colour of the text is fairly easy using ANSI terminal escape
sequences. For instance, to set the text colour to dark red, write "<Esc>
[31;2m" to the terminal (where <Esc> is the escape code - in emacs use
"C-q ESC" to write <Esc>). We can reset the output colour using "<Esc>
0m".

Printing the output of external programs in dark red, we can do using the
execute() function:

def runCommand(comm and):
print 'Running:', command

# set output colour:
sys.stdout.writ e("<Esc>[31;2m") ; sys.stdout.flus h()

os.system(comma nd)

# reset output colour
sys.stdout.writ e("<Esc>[0m")

(Here we need to flush the stdout file to make sure that the escape code
is written to the terminal before the output of the program)

http://www.daimi.au.dk/~mailund/scri...anagement.html

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2565
by: M.E.Farmer | last post by:
Hello c.l.py!, I have just finished this and decided to share. PySourceColor is a module to convert Python source into colored html. Yes it has been done before, but I like this better:) You can easily define your own colorscheme. example usage: # Highlight PySourceColor.py python PySourceColor.py or # Show help
77
3905
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the reStructuredText source as it is today. Please discuss it here so I can see what issues people may have.
14
2639
by: Omar | last post by:
1) why don't python / idle use numbered lines in their scripting, like basic? how do you keep track of large batches of code without them? 2) in IDLE, how do you save a program such that it can be run, say from windows the "run" function? 3) are most of you doing your script editing in IDLE or something more fully featured? 4) how are...
0
262
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 416 open (-14) / 3463 closed (+16) / 3879 total ( +2) Bugs : 930 open ( +8) / 6333 closed (+17) / 7263 total (+25) RFE : 244 open ( -1) / 244 closed ( +3) / 488 total ( +2) New / Reopened Patches ______________________
12
2992
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if...
1
5764
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for example: answer_str = raw_input(' Enter answer ') Herr Üü
0
7847
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7778
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8290
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6522
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5342
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1389
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.