要更改配色方案,请编辑 中的 [颜色] 部分config.txt
。然而,你不能在一个程序中这样做——即使你可以这样做,它的效率也会低得令人作呕。您无需安装任何新模块。你可以通过subprocess
Python 自带的一个模块来做到这一点。
就像是:
from subprocess import call
call('color a', shell=True) #this sets the color to light green
print('The quick brown fox jumps over the lazy dog.')
这适用于 Windows,您可以根据操作系统轻松更改调用的命令。对于您的程序,您可以将颜色放在一个for
循环中,随着print
语句中的消息而变化。
请注意,这仅在您从文件位置或命令行运行时才有效。当您在 IDLE 中运行它时,它将不起作用。希望我有所帮助!
编辑:您可以在此处找到颜色列表。语法是:color 'background ID''text ID'
.
这将允许您执行以下操作:
import time
from subprocess import call
for color in('a', 'e', 'c'): #cycles through different colours
call('cls', shell=True) #clears the screen
call('color ' + color, shell=True)
print('The quick brown fox jumps over the lazy dog.')
time.sleep(1)
input("\nPress enter to exit. ")
从那里,您可以修改代码以使用您选择的颜色。不幸的是,绝对不可能同时在屏幕上显示所有颜色。为此,恐怕您确实需要外部模块。