如何设置tqdm的默认进度条颜色和背景颜色?

4
我在Jupyter笔记本中使用tqdm库。通常我会看到一个白色背景上的绿色进度条。但是现在我看到一个粉色背景上的黑色进度条:
import tqdm, tqdm.notebook
from time import sleep

# first progress bar
for i in tqdm.notebook.tqdm(range(10)):
    sleep(.1)

# second progress bar
for i in tqdm.notebook.tqdm(range(10)):
    sleep(.1)
    
# third progress bar
for i in tqdm.tqdm(range(10)):
    sleep(.1)
    
# fourth progress bar
for i in tqdm.tqdm(range(10), colour='green'):
    sleep(.1)

生成了以下这四个进度条:

enter image description here

我想要的是一个绿色的进度条,没有粉色的背景。

在安装 PyQt5 后出现了这种行为变化。尽管我已经卸载了它,但行为仍然存在。

此外,我之前在笔记本中使用 tqdm.notebook.tqdm 进行进度条显示。现在该函数不再显示进度条(1和2号进度条)。我需要使用 tqdm.tqdm (3和4号进度条)。

我认为这个问题与后端有关。

1个回答

3

粉色背景表示输出到sys.stderr。使用tqdm参数file可以获得白色背景。要更改颜色,请使用参数colour

for i in tqdm (range(50), file=sys.stdout, colour = 'GREEN'):

有关更多信息,请参见tqdm文档


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接