I use the following code to make the text colored: stopLoss = float(input(colored("Enter stop loss price> ", 'red')))
. It works well wihtin Pycharm, but when I convert the python file to .exe file using pyinstaller, it outputs this: ←[31mEnter stop loss price> ←[0m20
. What should I do?
Asked
Active
Viewed 1,006 times
0

bassel2777
- 15
- 5
-
Answers are here: https://stackoverflow.com/questions/61701889/cannot-print-colored-text-on-windows – Prometheus May 23 '21 at 09:17
-
4Does this answer your question? [Cannot print colored text on Windows](https://stackoverflow.com/questions/61701889/cannot-print-colored-text-on-windows) – Prometheus May 23 '21 at 09:17
-
use colorama to change the color – Johan Jomy May 23 '21 at 09:37
2 Answers
0
On windows you can use:
import os
os.system('color 04') #red foreground color
color command syntax is: color *background* *foreground*
Here are the color codes
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

SEKTION
- 87
- 9
0
You can try colorama.
import colorama
colorama.init(True) # You dont need True, its so that you dont need to reset
# Text color after sending color all the time.
print(colorama.Fore.RED + "Hi!")
Would result in "Hi!" being printed as red color.
UPDATE:
You also need to install it, you can do so by:
pip install colorama
(Might change from OS to OS.)