How to Print Coloured Text in Terminal
by vigneshchennai74 Updated: Jan 31, 2023
A Python package called "colorama" enables you to print colourful text on the terminal. Both Windows and Linux/Unix systems are compatible with it, and it has the ability to recognise whether it is operating on Windows or not and adapt its behaviour accordingly.
There are several applications for colourful text printing on terminals, some of which are as follows:
- Debugging: You may rapidly find and discover mistakes in your code by printing coloured text, which makes debugging simpler.
- Status updates: Updates on the state of your code can be made using coloured text, such as if a task has been successfully completed or if an error has occurred.
- User interaction: Using coloured text to make your code output more aesthetically pleasing and approachable can increase user satisfaction and engagement.
- Logging: To make log files for debugging, monitoring, and troubleshooting your code simpler to see and analyse, you can use coloured text.
- Data visualization: Colored text can be used to visualise data by using color coding, making it easier to comprehend and analyse the information.
- CLI tools: Colored text can be used to enhance a command-line tool's user interface.
Here is how you can print coloured text in Terminal:
Preview of the output that you will get on running this code in your IDE
In this solution we have used Colorama Library.
import os os.system("color 3") # colour can be any number between 1 to 8 print("Your text") from colorama import init, Fore, Back, Style init(convert=True) print(Fore.RED + 'some red text') print(Back.GREEN + 'and with a green background') print(Style.DIM + 'and in dim text') print(Style.RESET_ALL) print('back to normal now')
- Copy this code using "Copy "button above and paste it in your python file IDE
- Add Colorama Library to run this code
- Run the code to get the texts coloured.
I hope you found this useful i have added the Dependent libraries , versions in the following sections
I have searched using "Print Coloured Text in Terminal" in Kandi. you can try any use case
I have tested this solution with following versions. Be mindful of changes when working with other versions
- This solution is created and executed in Python 3.7.15 version.
- This solution is tested on Colorama 0.4.6 version.
Using this solution we able to change the style , color, Brightness of the Text in Terminal using Colorama Library in python with simple steps. This process also facilities an easy to use, hassle free method to create a hands-on working version of code which would help us edit the text in Python.
Simple cross-platform colored terminal text in Python
Python 3128 Version:Current License: Permissive (BSD-3-Clause)
If you don't have this Colorama Library that required to run this code. You can install by clicking the above link and copying the pip install command from the Colorama page in Kandi. You can search any Library Like colorama in kandi
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.