1

enter image description here

These sequences are supposed to represent color and look something like this. Basically, colors displayed as background in the terminal.

It works normally on my terminal. But if someone else were to run the script by double-clicking on the file, by default it opens with the python one which displays it like this

←[48;2;107;53;184m  ←[49m←[48;2;222;167;58m  ←[49m←[48;2;180;204;110m  ←[49m←[48;2;161;60;55m  ←[49m
←[48;2;107;53;184m  ←[49m←[48;2;50;146;173m  ←[49m←[48;2;180;204;110m  ←[49m←[48;2;161;60;55m  ←[49m
.....

How can I fix this? I want the colors to be visible if someone else runs the program.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
ggmagg
  • 11
  • 2
  • can You show how it displays them on Your machine? also don't link media outside SO – Matiiss Apr 02 '21 at 02:34
  • @Matiiss thanks! just added a picture of what it should look like – ggmagg Apr 02 '21 at 03:27
  • What do you mean by "Python terminal"? I would assume IDLE, but I'm pretty sure ANSI codes work there. If you mean Windows Console in Windows 10, try this: [How can I make the ANSI escape codes to work also in Windows?](https://stackoverflow.com/q/12492810/4518341) Otherwise, you could take a look at this, but it's quite broad: [How to print colored text to the terminal?](https://stackoverflow.com/q/287871/4518341) – wjandrea Apr 02 '21 at 03:54
  • @wjandrea yes, more specifically I mean the interactive terminal that opens when you open any python script. That's true, it should work but doesn't. It runs perfectly fine when I run it manually on cmd, bash, and Powershell. But not the python one, which happens to be the one that opens by default when the file is double-clicked to 'run it'. – ggmagg Apr 02 '21 at 04:31
  • @ggmagg What terminal is that exactly? IDLE? – wjandrea Apr 02 '21 at 04:34
  • @wjandrea yes IDLE – ggmagg Apr 02 '21 at 04:41
  • @I guess You will have to run it on cmd then since it works there – Matiiss Apr 02 '21 at 10:38
  • Don't use ANSI sequences, [How to print colored text to the terminal?](https://stackoverflow.com/q/287871/5987) shows other options. – Mark Ransom Apr 02 '21 at 15:04
  • I guess the simple solution is to not use IDLE. It's not a great terminal anyway :| – wjandrea Apr 02 '21 at 19:08
  • this post talks about Colored and Colorama which also use ANSI sequences. I also think it is the only way to display colors on a terminal :( - @MarkRansom – ggmagg Apr 03 '21 at 03:59
  • Agreed! Unfortunately, it opens by default. I guess I should try to focus on changing this from within the program. Hopefully, I get it to open somewhere else. Thanks a lot! - @wjandrea – ggmagg Apr 03 '21 at 04:06
  • It also mentioned `curses` which I thought was more thorough, maybe I was wrong about that. – Mark Ransom Apr 03 '21 at 05:19

0 Answers0