954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing output color?

Hey guys,

Is it possible to change the color of characters in a list if they do/dont meet certain conditions? So here's my code:

def checkWord(real, guess, remReal, remGuess, wrongSpot):
    # Format the letters so user knows whats wrong/right
    fullWord= real
            
    # Create copy list of real word
    realWord= list(fullWord)

    # Create index start point
    index= 0

    # Iterate for each letter in 'guess'
    for letter in guess:
        #print(letter)

        # Print letter with '[]' if it is in the wrong positon list 
        if letter in wrongSpot:
            print('[',letter,']',end='')
            # Convert letter in list to a '*'
            realWord[index]= '*'
            # Add to accumulator value
            index+=1
            # Debug
            #print (realWord)
            
        # If the letter is one of the remaining letters in the guess list but
        # it's not in the current word list so it is not in the real word,
        # print only the letter
        elif letter in remGuess and letter not in realWord:
            print(letter,end='')
            realWord[index]= '*'
            index+=1
            #print (realWord)

        # Print letter with '()' if letter is in the current word list
        elif letter in realWord:
            print('(',letter,')',end='')
            realWord[index]= '*'
            index+=1

I want the LIST characters to be changed to yellow if the first if condition is met, red and italic if the second elif condition is met, and green and bold if the last elif is met. Is there a way to go about doing this where the output prints into the shell?

carmstr4
Newbie Poster
6 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

It depends on your output shell. If you are using python in a terminal, you can print in colors with this module http://pypi.python.org/pypi/colorama . On the other hand, it won't work if you are using idle or another IDE with a graphical user interface (each GUI widget has its own rules to display text in colors, and idle for example has no user API to do this).

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 
It depends on your output shell. If you are using python in a terminal, you can print in colors with this module http://pypi.python.org/pypi/colorama . On the other hand, it won't work if you are using idle or another IDE with a graphical user interface (each GUI widget has its own rules to display text in colors, and idle for example has no user API to do this).

Ok thanks!

carmstr4
Newbie Poster
6 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: