您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在python 3.3.2中更改外壳打印颜色

在python 3.3.2中更改外壳打印颜色

要更改配色方案,请在中编辑[颜色]部分config.txt。但是,您无法在程序执行期间执行此操作,即使您这样做,效率也非常低。您无需安装任何新模块。您可以通过subprocessPython附带的模块来执行此操作。

就像是:

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. ")

由此,您可以修改代码以使用您选择的颜色。不幸的是,绝对不可能同时在屏幕上显示所有颜色。对于您 需要外部模块,我害怕。

python 2022/1/1 18:28:39 有403人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶