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

发布于 2025-01-14 16:18:36 字数 818 浏览 2 评论 0 原文

我在 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 条)。

我认为问题与后端有关。

I'm using tqdm in a Jupiter notebook. Normally I would see a green progress bar on a white background. However, now I see a black progress bar on a pink background:

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)

produces these four bars:

enter image description here

What I want is a green progress bar, without the pink background.

This change in behaviour appeared after I installed PyQt5. I've uninstalled but behaviour remains.

Also, previously I used tqdm.notebook.tqdm in my notebook for progress bars. Now that function does not display a progress bar (bars 1 and 2). I need to use tqdm.tqdm (bars 3 and 4).

I assume the issue is something to do with the backend.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄情伤 2025-01-21 16:18:36

粉红色背景意味着输出转到 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 parameter file. To change color use parameter colour:

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

see more info in tqdm docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文