#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Colours in the command prompt!


    Hey.
    I need to change the color of one word when I run my program in the command prompt (i.e. run it by double clicking on the .py file)
    I searched and found this function. (a little altered for my need)

    PHP Code:
    def changeColor(colorID):
        
    windll.Kernel32.GetStdHandle.restype c_ulong
        h 
    windll.Kernel32.GetStdHandle(c_ulong(0xfffffff5))
        
    windll.Kernel32.SetConsoleTextAttribute(hcolorID
    The thing is, all it can do is change the color of a single line.
    Tried this:

    PHP Code:
    print("I will call it "), end="")
    changeColor(4)
    print(
    newNameend="");
    changeColor(2)
    print(
    "!"); 
    But it would only change the color of the line to 2 and to 4 if I removed the changeColor(2) line. So does anyone know any way to change the color of just one word?

    Thanks in advance
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    http://ascii-table.com/ansi-escape-sequences.php

    examples in many computer languages
    Last edited by b49P23TIvg; December 16th, 2012 at 01:26 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0


    Thank you for your reply! I didn't have time to test it before now and got this

    PHP Code:
    Traceback (most recent call last):
      
    File "D:\~ Programming\Python\PYTHON\Test.py"line 4in <module>
        
    import colorama
    ImportError
    No module named 'colorama' 
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    I take it you didn't bother to search the internet for colorama, nor did you bother to learn about ANSI terminal control sequences.
    https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1#hl=en&tbo=d&qscrl=1&sclient=psy-ab&q=colorama.py&oq=&gs_l=&pbx=1&qscrl=1&fp=d518ec0f384933bc&bpcl=39967673&ion=1&bav=on.2,or.r_gc.r_ pw.r_cp.r_qf.&bvm=bv.1355325884,d.dmQ&biw=949&bih=532
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo