3

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

actually just os.system("") (if you wanna fix it without clearing screen) works too its actually something with the default terminal window on windows be it for cmd or powershell its the same, it works without doing this however if you're using windows terminal or the vs code terminal and since when you package your app with pyinstaller its probably opening the default cmd window it needs that weird hack

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.