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 :: import pandas 
Python :: python input with space 
Python :: check if directory exists python 
Python :: python trim string to length 
Python :: how to openn file dialog in tkinter 
Python :: flask app example 
Python :: Python create a digital clock 
Python :: pandas groupby sum 
Python :: how to print items in a list in a single line python 
Python :: converting a string to a dictionary in python 
Python :: converting column data to sha256 pandas 
Python :: absolut beginners projects in python with tutorial 
Python :: python specify typeError output 
Python :: per gjera te shumta. Python 
Python :: media url django 
Python :: how to add stylesheet in django 
Python :: set x label matplotlib 
Python :: python interpreter clear screen 
Python :: download from radio javan python 
Python :: in 2002 elon musk age 
Python :: list python shuffling 
Python :: jupyter notebook for loop progress bar 
Python :: numpy distance between two points 
Python :: python -m http 
Python :: truncate add weird symbols in python 
Python :: remove 0 values from dataframe 
Python :: how to get started with python 
Python :: python run exe with arguments 
Python :: how to check if user is using main file or importing the file and using in python 
Python :: converting capital letters to lowercase and viceversa in python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =