在 VSCode Jupyter 笔记本中使 tqdm bar 变暗

make tqdm bar dark in VSCode Jupyter notebook

提问人:Sadra 提问时间:3/19/2022 最后编辑:Sadra 更新时间:5/20/2023 访问量:1962

问:

我在启用了深色模式的 Visual Studio Code 中使用 Jupyter 笔记本。我用 tqdm 可视化进度条,但它没有显示为深色。看图片:enter image description here

根据 GitHub 上的这个问题,这不是 Jupyter、ipywidget 或 tqdm 本身的问题,它只与 VSCode 有关。

有什么解决方法可以解决这个问题吗?

python visual-studio-code jupyter-notebook

评论

0赞 omasoud 12/22/2022
有点笨拙的解决方法包括执行以下两项操作:(1) 在 vscode 中将默认的 pywidgets 背景颜色设置为黑色:请参阅链接和 (2) 将文本颜色的小部件样式设置为 IPython 单元运行前事件(以获取白色文本):请参阅链接

答:

0赞 SriSreedhar 4/10/2023 #1

您可以使用使用 ANSI 转义码设置颜色的自定义格式将 tqdm-bar_format 参数传递给 tqdm

像这样的东西:

from tqdm import tqdm
import time

# Custom format with ANSI escape codes for dark green color
dark_green = "\033[1;32;40m"
bar_format = f"{dark_green}{{l_bar}}{{bar:50}} [{{elapsed}}]{{r_bar}}"

# Create tqdm progress bar with custom format
for i in tqdm(range(100), bar_format=bar_format):
    time.sleep(0.01)

此外,This-Post 可能会有所帮助。

0赞 walksonair 5/20/2023 #2

我遇到了同样的问题,我的搜索显示,在单元格中单独输入以下内容可以解决背景显示问题,但文本变暗可能是深色背景上的问题。作为折衷方案,我将我的设置为桃色页面(见屏幕截图):

%%html
<style>
.cell-output-ipywidget-background {
   background-color: transparent !important;
}
.jp-OutputArea-output {
   background-color: transparent;
}  
</style>

enter image description here

0赞 mentoc3000 11/29/2023 #3

这个答案对我有用。在单元格中运行下面的代码。

%%html
<style>
.cell-output-ipywidget-background {
    background-color: transparent !important;
}
:root {
    --jp-widgets-color: var(--vscode-editor-foreground);
    --jp-widgets-font-size: var(--vscode-editor-font-size);
}  
</style>