0

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

Cardstdani
  • 4,999
  • 3
  • 12
  • 31
cl.ement05
  • 25
  • 1
  • 6
  • See [this](https://stackoverflow.com/q/2048509/3282436) question for a couple scripts to make sure that your console supports colors in the first place. – 0x5453 Apr 15 '20 at 12:45
  • You need to specify which console app you are using, are you using cmd? or powershell? or anacondaprompt? or something else? I just tried lazyme.color_print in Spyder console on my win pc, and there it works.. I also tried it in anacondaprompt on the same win pc, there it does not work.. I haven't tried in cmd or powershell because there my win path vars are not set up correctly for me to run python on this pc. – Vinzent Apr 15 '20 at 12:59
  • 1
    @0x5453 Lol this is strange because printy worked for me but when I test my console for color support with the link, it does not work – cl.ement05 Apr 15 '20 at 13:02
  • 1
    @Vinzent I am using cmd and PowerShell. Both do not work – cl.ement05 Apr 15 '20 at 13:03

1 Answers1

1

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

  • Sooo many thanks !! It worked both on Windows and Linux ! Thanks a lot – cl.ement05 Apr 15 '20 at 12:57
  • you're welcome boss. If you find something that you think it's not working properly on your Windows machine, or you think that something could be improved, don't hesitate in letting us know by adding a new issue! – Edgardo Obregón Apr 15 '20 at 13:04