You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jupyter Notebook主题自定义咨询:修改monokai主题背景为纯黑

Hey there! Great question—customizing Jupyter Notebook themes to fit your preference is totally straightforward. Let's walk through two reliable ways to tweak the monokai theme and get that pure black background you're after.

Method 1: Use jupyterthemes Command-Line Flags (If You Installed Themes via jt)

If you used the popular jupyterthemes package to install monokai, you can override the background color directly with a terminal command. Run this:

jt -t monokai -bg '#000000' -T -N

Here's a quick breakdown of the key flags:

  • -t monokai: Tells jupyterthemes to use the monokai base theme
  • -bg '#000000': Sets the notebook's background to pure black (hex code #000000)
  • -T -N: Keeps the toolbar and notebook title visible (omit these if you prefer a cleaner look)

Feel free to add other flags like -f fira (font choice) or -fs 13 (font size) to tweak things further. After running the command, restart your Jupyter server and refresh your browser to see the change.

Method 2: Manually Edit CSS (For More Control)

If the command-line approach doesn't work for your setup, or you want more granular control, you can edit the CSS directly:

  • First, locate your Jupyter custom CSS file. On most systems, this is ~/.jupyter/custom/custom.css (macOS/Linux) or C:\Users\[YourName]\.jupyter\custom\custom.css (Windows). If the file doesn't exist, create it.
  • Open the file in a text editor and add this snippet:
    /* Override monokai background to pure black */
    .jp-Notebook {
        background-color: #000000 !important;
    }
    
    The !important tag ensures this style takes priority over the monokai theme's default background.
  • If you're using an older version of Jupyter where the selector is different, try this instead:
    body.notebook_app {
        background-color: #000000 !important;
    }
    
  • Save the file, restart your Jupyter server, and refresh the browser—your notebook background should now be pure black.

Pro Tip: Avoid Editing Core Theme Files

I recommend using the custom.css file instead of modifying the monokai theme's original CSS (which lives in your Python site-packages). This way, if you update the monokai theme later, your custom background setting won't be overwritten.

内容的提问来源于stack exchange,提问作者Phcem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:03:52