pythonjtextcomponent

Add text color while print - Python


I want to add text color while print output. How to do that ?

Example: Print('Hello Everyone.') I want output text Hello Everyone will highlighted red color.

Thanks you!


Solution

  • An easy way to do this is to import a color module like colorama or termcolor. This site might be useful: Print Colors in Python terminal. For you code it would be:

    from colorama import Fore
    print(Fore.RED + 'Hello Everyone') 
    

    or

    import sys 
    from termcolor import colored, cprint
    print(colored('Hello Everyone', 'red'))  # method one
    cprint('Hello Everyone', 'red')          # method two