要更改配色方案,请在中编辑[颜色]部分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. ")