我目前正在制作一个很长的Python程序(很抱歉,我无法在这里发布它,因为它的长度为400行),我想打印彩色的Text。我知道已经有人问过这个问题,但他们只在Linux上工作(对我来说...)。我使用termcolor模块。这是程序的一部分:
if user_id_signin == user_id :
print('Welcome', colored(name_signin, 'red'))
但是当我在Raspberry Pi上运行代码时,我得到以下输出:
我已经检查了Pip,并且所有必需的模块都已安装在Windows PC上... 我还尝试了其他方法(使用colorama模块),但得到的还是相同的结果
为什么这仅在Windows上不起作用?
感谢帮助我 (对不起,我的英语)
克莱门特
答案 0 :(得分:0)
我建议这个新图书馆印刷 刚刚发布了1.2.0版作为跨平台库。
签出: Printy on github
它基于标志,因此您可以做类似的事情
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")