【问题标题】:How to change text color from a python module (tqdm module) output ? (so not python text editor output)如何从 python 模块(tqdm 模块)输出更改文本颜色? (所以不是python文本编辑器输出)
【发布时间】:2021-03-23 22:18:29
【问题描述】:

我在 Google Colab 中使用深色主题,它会自动将文本颜色从输出转换为白色。 但是,现在我正在使用 TQDM 模块中的进度条,我得到的文本是深色的,这在深色主题中是有问题的。我在考虑 Colorama,但它只会更改文本编辑的文本颜色(我认为?)。这是我的代码:

import yahoo_fin
from yahoo_fin.stock_info import get_data
bar = trange(72)
bar.write("Downloading data...")
for i,stocks in zip(bar,filtered_list):
    df[stocks]= get_data(stocks,stockstart,stockend)['adjclose'].dropna()
bar.write("Completed!") 

【问题讨论】:

    标签: python text colors


    【解决方案1】:

    我在 Colab 中遇到了这个问题,在单元格中运行以下代码为我解决了这个问题:

    # Set the tqdm text color to white.
    
    from IPython.display import HTML, display
    
    def set_css_in_cell_output():
        display(HTML('''
            <style>
                .jupyter-widgets {color: #d5d5d5 !important;}
                .widget-label {color: #d5d5d5 !important;}
            </style>
        '''))
    
    get_ipython().events.register('pre_run_cell', set_css_in_cell_output)
    

    (灵感来自this StackOverflow 答案)

    【讨论】:

      猜你喜欢
      • 2014-09-03
      • 2017-12-22
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 2015-05-30
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多