Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add color to python text

# You can use colorama for changing the text color here is a example of that 
from ast import For
from random import random
from random import randint
'''
First Install colorama by typing this in the terminal:
python -m pip install colorama or simply pip install colorama
'''
import colorama
from colorama import Fore,Back,Style
colorama.init(autoreset=True)

# Now here back is for background and Fore is for text color.
while(0<10):
    eyt = input("Enter your text - ")
    wcib= input("Enter your colour for back - ")
    # wcib= wcib.upper()
    wcif= input("Enter your colour for text - ")
    # wcif= wcif.upper()
    if(wcib == "black" and wcif == "red"):
        print(Back.BLACK + Fore.RED  + eyt)
    if(wcib == "black" and wcif == "blue"):
        print(Back.BLACK + Fore.BLUE  + eyt)
    else:
        randoma=randint(1,6)
        if(randoma == 1):
            print(Back.BLACK+Fore.LIGHTGREEN_EX+"We are sorry we dont have that in our library")
        if(randoma == 2):
            print(Back.BLACK+Fore.LIGHTBLACK_EX+"We are sorry we dont have that in our library")
        if(randoma == 3):
            print(Back.BLACK+Fore.LIGHTCYAN_EX+"We are sorry we dont have that in our library")
        if(randoma == 4):
            print(Back.BLACK+Fore.LIGHTMAGENTA_EX+"We are sorry we dont have that in our library")
        if(randoma == 5):
            print(Back.BLACK+Fore.LIGHTRED_EX+"We are sorry we dont have that in our library")
        if(randoma == 6):
            print(Back.BLACK+Fore.LIGHTYELLOW_EX+"We are sorry we dont have that in our library")
            
  '''
colors present - 
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Style: DIM, NORMAL, BRIGHT, RESET_ALL
'''
Comment

add colour to text in python


class bcolors:
    HEADER = '33[95m'
    OKBLUE = '33[94m'
    OKCYAN = '33[96m'
    OKGREEN = '33[92m'
    WARNING = '33[93m'
    FAIL = '33[91m'
    ENDC = '33[0m'
    BOLD = '33[1m'
    UNDERLINE = '33[4m'

Comment

how to add colors in python

#install colorama module
from colorama import Fore
blue = Fore.BLUE
print(f"{blue} blue text")
Comment

PREVIOUS NEXT
Code Example
Python :: python string index 
Python :: convert date to integer python 
Python :: abstract classes in python 
Python :: create a pandas dataframe 
Python :: range() in python 
Python :: python find last index of character in string 
Python :: scikit decision tree regressor 
Python :: join python 
Python :: readline python 
Python :: start and end index in python 
Python :: k fold cross validation 
Python :: python bool() 
Python :: python array use numpy arange 
Python :: youtube bot python 
Python :: how to access variable of one function in another function in python 
Python :: python ValueError: zero-size array to reduction operation maximum which has no identity 
Python :: get dataframe name python 
Python :: create a range of numbers in python 
Python :: how to send a command to cmd using python 
Python :: what is repr function in python 
Python :: show which columns in dataframe have NA 
Python :: python glob how to read all txt files in folder 
Python :: python press any key to continue 
Python :: program in python to print first 10 natural number. 
Python :: python xgboost 
Python :: how to make a calculator in python 
Python :: django model queries 
Python :: k means clustering python medium 
Python :: install multiple versions of python 
Python :: how to represent equation in pytho 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =