Home > front end >  Console color issue
Console color issue

Time:12-24

I am writing a python program with a header that is meant to be colored blue. I am using the art library to generate text and some color codes but things just don't make sense.

Here is the code for the program font-test.py

from art import *
import ctypes
kernel32 = ctypes.WinDLL('kernel32')
hStdOut = kernel32.GetStdHandle(-11)
mode = ctypes.c_ulong()
kernel32.GetConsoleMode(hStdOut, ctypes.byref(mode))
mode.value |= 4
kernel32.SetConsoleMode(hStdOut, mode)


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

Art=text2art(f"{bcolors.OKBLUE}COOL HEADER{bcolors.ENDC}",font='graffiti',chr_ignore=True) # Return ASCII text with block font
print(Art)

This is the output from running >> python font-test.py output I expected it to simply print the text "COOL HEADER" in blue.

CodePudding user response:

With the help of text2art you can generate the string. If you want to print this string in a different color, you can do this in the print() function, as shown below:

Art=text2art("COOL HEADER",font='graffiti',chr_ignore=True)
print(bcolors.OKBLUE   Art   bcolors.ENDC)
  • Related