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

python color text

#example
print("33[1;31mHello World!33[0m")

print("33[<properties>;<color>m")

Black	30	No effect	0	Black	40
Red		31	Bold		1	Red		41
Green	32	Underline	2	Green	42
Yellow	33	Negative1	3	Yellow	43
Blue	34	Negative2	5	Blue	44
Purple	35					Purple	45
Cyan	36					Cyan	46
White	37					White	47
Comment

python text color

from termcolor import colored
print(colored('python', 'green', attrs=['bold']))
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 :: how to plot pie chart in python 
Python :: decision tree classifier 
Python :: prevent list index out of range python 
Python :: string to list separated by space python 
Python :: how to close a webpage using selenium driver python 
Python :: python print class variables 
Python :: how to count unique values in a column dataframe in python 
Python :: how to get only certain columns in pandas 
Python :: how to add element at first position in array python 
Python :: index of max in tensor 
Python :: case statement in querset django 
Python :: select specific rows from dataframe in python 
Python :: python xml replace attribute value 
Python :: pandas str is in list 
Python :: python tkinter define window size 
Python :: what is python used for 
Python :: python find number of occurrences in list 
Python :: calcutalte average python 
Python :: create fixtures django 
Python :: How to draw a rectangle in cv2 
Python :: pandas read csv skip first line 
Python :: how to search a file in windows 10 using python 
Python :: how to check if given number is binary in pytho 
Python :: how to use virtual environment python 
Python :: df.select_dtypes 
Python :: geometrical mean python 
Python :: python pair two lists into a dictionary 
Python :: checking if a string is in alphabetical order in python 
Python :: python pandas replace not working 
Python :: anova test in python 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =