cl.ement05
cl.ement05

Reputation: 25

How to print colored text with Python in Windows

I am currently making a very long Python program (sorry I cannot post it here since it is 400 lines long) and I wanted to print colored Text. I know this question has already been asked but they only worked with Linux (for me...). I use the termcolor module. Here is a part of the program :

if user_id_signin == user_id :
    print('Welcome', colored(name_signin, 'red'))

When I run this code on Windows I get this output : enter image description here

But when I run my code on my Raspberry Pi I get this output : enter image description here

I have checked Pip and all required modules are installed on my Windows PC... I have also tried other methods (with colorama module) and I get the same thing

Why is this not working only on Windows ?

Thanks for helping me (and sorry for my English)

Clement

Upvotes: 0

Views: 785

Answers (1)

Edgardo Obregón
Edgardo Obregón

Reputation: 447

I suggest this new library Printy Just released version 1.2.0 as a cross-platform library.

Check it out: Printy on github

It is based on flags so you can do stuff like

from printy import printy

# with global flags, this will apply a bold (B) red (r) color and an underline (U) to the whole text
printy("Hello world", "rBU")

# with inline formats, this will apply a dim(D)
#blue (b) to the word 'Hello' and a striked (S)
#yellow (y) to the word 'world', the rest will remain as the predefined format
printy("this is a [bD]Hello@ [yS]world@ text")

enter image description here

Upvotes: 1

Related Questions