xxxxxxxxxx
#example
print("\033[1;31mHello World!\033[0m")
print("\033[<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
xxxxxxxxxx
def colored(r, g, b, text):
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
text = 'Hello, World'
colored_text = colored(255, 0, 0, text)
print(colored_text)
#or
print(colored(255, 0, 0, 'Hello, World'))
xxxxxxxxxx
#colors
ResetAll = "\033[0m"
Bold = "\033[1m"
Dim = "\033[2m"
Underlined = "\033[4m"
Blink = "\033[5m"
Reverse = "\033[7m"
Hidden = "\033[8m"
ResetBold = "\033[21m"
ResetDim = "\033[22m"
ResetUnderlined = "\033[24m"
ResetBlink = "\033[25m"
ResetReverse = "\033[27m"
ResetHidden = "\033[28m"
Default = "\033[39m"
Black = "\033[30m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Magenta = "\033[35m"
Cyan = "\033[36m"
LightGray = "\033[37m"
DarkGray = "\033[90m"
LightRed = "\033[91m"
LightGreen = "\033[92m"
LightYellow = "\033[93m"
LightBlue = "\033[94m"
LightMagenta = "\033[95m"
LightCyan = "\033[96m"
White = "\033[97m"
xxxxxxxxxx
import colorama
from colorama import Fore
print(Fore.RED + 'This text is red in color')
xxxxxxxxxx
from colorama import init
from colorama import Fore
init()
print(Fore.BLUE + 'Hello')
print(Fore.RED + 'Hello')
print(Fore.YELLOW + 'Hello')
print(Fore.GREEN + 'Hello')
print(Fore.WHITE + 'Hello')
#test in vscode
#code by fawlid
xxxxxxxxxx
# 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
'''
xxxxxxxxxx
import colorama
from colorama import Fore
print(Fore.RED + 'This text is red in color')
xxxxxxxxxx
from colorama import Fore
from colorama import Style
print(f"This is {Fore.GREEN}color{Style.RESET_ALL}!")
xxxxxxxxxx
class Foreground:
RESET = "\033[0m"
RED = "\033[38;2;255;0;0m"
REDORANGE = "\033[38;2;255;82;0m"
ORANGE = "\033[38;2;255;165;0m"
ORANGEYELLOW = "\033[38;2;255;210;0m"
YELLOW = "\033[38;2;255;255;0m"
YELLOWGREEN = "\033[38;2;180;255;0m"
GREEN = "\033[38;2;0;255;0m"
GREENBLUE = "\033[38;2;0;180;180m"
BLUE = "\033[38;2;0;0;255m"
BLUEPURPLE = "\033[38;2;75;0;202m"
PURPLE = "\033[38;2;150;0;150m"
BOLD = "\033[38;2;255;255;255;1m"
ITALIC = "\033[38;2;255;255;255;3m"
UNDERLINE = "\033[38;2;255;255;255;4m"
REVERSE = "\033[38;2;255;255;255;7m"
DIM = "\033[38;2;255;255;255;2m"
def _hextorgb(hexcode):
hexcode = str(hexcode)
if hexcode[0] == "#":
hexcode = hexcode[1:]
r, g, b = hexcode[0:2], hexcode[2:4], hexcode[4:6]
r, g, b = int(hex(int(r, 16)), 16), int(hex(int(g, 16)), 16), int(hex(int(b, 16)), 16)
return (r, g, b)
def customrgb(rgb):
r, g, b = rgb
return f"\033[38;2;{r};{g};{b}m"
def customhex(hexcode):
hexcode = str(hexcode)
if hexcode[0] == "#":
hexcode = hexcode[1:]
r, g, b = hexcode[0:2], hexcode[2:4], hexcode[4:6]
r, g, b = int(hex(int(r, 16)), 16), int(hex(int(g, 16)), 16), int(hex(int(b, 16)), 16)
return f"\033[38;2;{r};{g};{b}m"
class Background:
RESET = "\033[0m"
RED = "\033[48;2;255;0;0m"
REDORANGE = "\033[48;2;255;82;0m"
ORANGE = "\033[48;2;255;165;0m"
ORANGEYELLOW = "\033[48;2;255;210;0m"
YELLOW = "\033[48;2;255;255;0m"
YELLOWGREEN = "\033[48;2;180;255;0m"
GREEN = "\033[48;2;0;255;0m"
GREENBLUE = "\033[48;2;0;180;180m"
BLUE = "\033[48;2;0;0;255m"
BLUEPURPLE = "\033[48;2;75;0;202m"
PURPLE = "\033[48;2;150;0;150m"
REVERSE = "\033[48;2;255;255;255;7m"
def _hextorgb(hexcode):
hexcode = str(hexcode)
if hexcode[0] == "#":
hexcode = hexcode[1:]
r, g, b = hexcode[0:2], hexcode[2:4], hexcode[4:6]
r, g, b = int(hex(int(r, 16)), 16), int(hex(int(g, 16)), 16), int(hex(int(b, 16)), 16)
return (r, g, b)
def customrgb(rgb):
r, g, b = rgb
return f"\033[48;2;{r};{g};{b}m"
def customhex(hexcode):
hexcode = str(hexcode)
if hexcode[0] == "#":
hexcode = hexcode[1:]
r, g, b = hexcode[0:2], hexcode[2:4], hexcode[4:6]
r, g, b = int(hex(int(r, 16)), 16), int(hex(int(g, 16)), 16), int(hex(int(b, 16)), 16)
return f"\033[48;2;{r};{g};{b}m"
# Save this code in a file named colors.py
# Then in your code add an import
# to here
xxxxxxxxxx
from termcolor import colored
print(colored('python', 'green', attrs=['bold']))