如何设置 tqdm 的默认进度条颜色和背景颜色?
我在 Jupiter 笔记本中使用 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)
产生这四个条:
我想要的是绿色进度条,没有粉红色背景。
我安装 PyQt5 后出现了这种行为变化。我已经卸载了,但行为仍然存在。
另外,之前我在笔记本中使用了 tqdm.notebook.tqdm
作为进度条。现在该函数不显示进度条(条 1 和条 2)。我需要使用 tqdm.tqdm(第 3 条和第 4 条)。
我认为问题与后端有关。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
粉红色背景意味着输出转到 sys.stderr 。要获得白色背景,请使用 tqdm 参数
file
。要更改颜色,请使用参数colour
:for i in tqdm(range(50), file=sys.stdout, color='GREEN'):
请参阅tqdm 文档
the pink background means that the output goes to
sys.stderr
. To have white background use tqdm parameterfile
. To change color use parametercolour
:for i in tqdm(range(50), file=sys.stdout, colour='GREEN'):
see more info in tqdm docs