Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改python中文本的颜色?_Python_Python 3.x - Fatal编程技术网

如何更改python中文本的颜色?

如何更改python中文本的颜色?,python,python-3.x,Python,Python 3.x,我制作了一个程序,其中我有两个单独的玩家,当玩家在我的游戏中进行时,我希望能够清楚地知道玩家的分数是多少,例如,我希望Player1文本是红色的,但Player2是蓝色的,既然windows上的Python 3没有颜色模块,那么还有什么办法这样做呢 if sum == 1: print("Since you rolled an odd you have lost 5 points") x=x+1-5 if sum == 2: print("Since you rol

我制作了一个程序,其中我有两个单独的玩家,当玩家在我的游戏中进行时,我希望能够清楚地知道玩家的分数是多少,例如,我希望Player1文本是红色的,但Player2是蓝色的,既然windows上的Python 3没有颜色模块,那么还有什么办法这样做呢

  if sum == 1:
    print("Since you rolled an odd you have lost 5 points")
    x=x+1-5

if sum == 2:
    print("Since you rolled an even you have gained 10 points")
    x=x+2+10

if sum == 3:
    print("Since you rolled an odd you have lost 5 points")
    x=x+3-5

if sum == 4:
    print("Since you rolled an even you have gained 10 points")
    x=x+4+10

if sum == 5:
    print("Since you rolled an odd you have lost 5 points")
    x=x+5-5

if sum == 6:
    print("Since you rolled an even you have gained 10 points")
    x=x+6+10

if sum == 7:
    print("Since you rolled an odd you have lost 5 points")
    x=x+7-5

if sum == 8:
    print("Since you rolled an even you have gained 10 points")
    x=x+8+10

if sum == 9:
    print("Since you rolled an odd you have lost 5 points")
    x=x+9-5

if sum == 10:
    print("Since you rolled an even you have gained 10 points")
    x=x+10+10

if sum == 11:
    print("Since you rolled an odd you have lost 5 points")
    x=x+11-5

if sum == 12:
    print("Since you rolled an even you have gained 10 points")
    x=x+12+10
我希望这个播放器的输出是默认的蓝色,但是

 if sum == 1:
    print("Since you rolled a odd you have lost 5 points")
    y=y+1-5   

if sum == 2:
    print("Since you rolled a even you have gained 10 points")
    y=y+2-10

if sum == 3:
    print("Since you rolled a odd you have lost 5 points")
    y=y+3-5

if sum == 4:
    print("Since you rolled a even you have gained 10 points")
    y=y+4+10

if sum == 5:
    print("Since you rolled a odd you have lost 5 points")                
    y=y+5-5                                         

if sum == 6:
    print("Since you rolled a even you have gained 10 points")
    y=y+6+10

if sum == 7:
    print("Since you rolled a odd you have lost 5 points")
    y=y+7-5

if sum == 8: 
    print("Since you rolled a even you have gained 10 points")
    y=y+8+10

if sum == 9:
    print("Since you rolled a odd you have lost 5 points")
    y=y+9-5

if sum == 10:
    print("Since you rolled a even you have gained 10 points")
    y=y+10+10

if sum == 11:
    print("Since you rolled a odd you have lost 5 points")
    y=y+11-5

if sum == 12:
    print("Since you rolled a even you have gained 10 points")
    y=y+12+10

此播放器输出为红色或任何其他颜色,请提供帮助?

您可以使用colorama模块执行此操作:pypi.python.org/pypi/colorama-查看他们的文档和屏幕截图

下面是一些示例代码:

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

但是,您需要在命令行中运行此操作,而在python shell中无法真正执行此操作

您可以提供一些最简单的示例代码吗?您是说(在终端中)基于文本的界面吗?Windows 10和大多数其他终端一样,编程语言与此无关。这取决于什么在侵蚀你的产出。如果您要打印到控制台,那么大多数都支持颜色、移动光标等。如果您使用的是GUI工具包,那么您需要在其API中工作。这里显示的代码与您的问题有什么关系?你试过/研究过什么?因为当我运行代码时,他们有两个不同的变量(y和x),所有这些看起来都属于一个玩家,即使有间距,所以我想让一个玩家输出不同的颜色,这样很明显scote属于谁