Python colour / formatting not working in pyinstaller

Viewed 227

I have the following python class taken from a question on here:

class color:
    PURPLE = '\033[95m'
    CYAN = '\033[96m'
    DARKCYAN = '\033[36m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    YELLOW = '\033[93m'
    RED = '\033[91m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    END = '\033[0m'

If I run my python program normally I can use a line of code such as this:

print(color.BOLD + "Welcome to the game" + color.END)

It will print in bold and underlined just fine.

I am using the following code to get pyinstaller to make a onefile exe

pyinstaller -c --onefile main.py

Pyinstaller creates this file fine and I can run it but the same code nows prints:

←[1m & ←[0m where \033[1m and \033[0m are.

The expected output is:

Welcome to the game

Actual output when running pyinstaller exe file is:

←[1mWelcome to the game←[0m

Is there any way to fix this?

Thanks

1 Answers

I recently found a way to apply color formatting in python:

import os
os.system('cls') # Clears the console screen

Put the rest of your code below and it will work normally. Tested it with PyInstaller and it works too.

Related