[英]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.我目前正在制作一个很长的 Python 程序(对不起,我不能在这里发布它,因为它有 400 行长),我想打印彩色文本。 I know this question has already been asked but they only worked with Linux (for me...).
我知道这个问题已经被问过了,但他们只与 Linux 合作(对我来说......)。 I use the
termcolor
module.我使用
termcolor
模块。 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:当我在 Windows 上运行此代码时,我得到此 output:
But when I run my code on my Raspberry Pi I get this output:但是当我在我的树莓派上运行我的代码时,我得到了这个 output:
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我已经检查了 Pip 并且所有必需的模块都安装在我的 Windows PC 上...我还尝试了其他方法(使用 colorama 模块),我得到了同样的结果
Why is this not working only on Windows?为什么这不适用于 Windows?
Thanks for helping me (and sorry for my English)谢谢你帮助我(对不起我的英语)
Clement克莱门特
I suggest this new library Printy Just released version 1.2.0 as a cross-platform library.我建议这个新库Printy刚刚发布了 1.2.0 版作为跨平台库。
Check it out: Printy on github看看:在 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.