# 使用交互式小部件

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

> **Warning:**
> 以下内容仅在 Python 和 Jupyter 插件 [已安装并启用](managing-plugins.html)时有效！

IntelliJ IDEA 支持交互式小部件，提供在笔记本内核中运行的 Python 代码与在浏览器中运行的 JavaScript 之间的集成。

有关交互式微件的种类和详细信息，请参阅 [Jupyter 微件文档](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html)。

## 将 widget 代码添加到您的 Jupyter notebook

要在您的笔记本中添加交互式小部件，首先添加一个代码单元格。

要预览这些小部件，您需要 [执行](running-jupyter-notebook-cells.html#execute-cell)相应的代码单元。

> **Note:**
> 切换 IntelliJ IDEA 主题时，交互式输出的背景颜色会在执行代码单元后发生变化

浅色:

![浅色主题中的交互式微件输出视图](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_interactive_output_light.png)

深色:

![浅色主题中的交互式微件输出视图](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_interactive_output_dark.png)

## 处理安全要求

如果打开在项目外创建的 Notebook 文件中的任何 JavaScript 或 HTML 代码，该 Notebook 将被视为不受信任。 根据为 Jupyter Notebook 建立的 [安全模型](https://jupyter-notebook.readthedocs.io/en/4.x/security.html)，不受信任的 JavaScript 代码绝不会执行，并且不受信任的 HTML 代码始终会经过清理。

因此，例如，当尝试在这样的 Notebook 中执行 HTML 时，将收到错误消息：  `This output uses HTML that may be stripped because the notebook is not trusted` 。

点击 Jupyter Notebook 工具栏上的   信任 Notebook   复选框，或点击   标记笔记本为可信  ，以明确允许在 Jupyter Notebook 中执行 HTML (JavaScript)。

![将 Notebook 设为可信](https://resources.jetbrains.com.cn/help/img/idea/2026.3/py_ipwidgets_trusted.png)

## See also

### 语言和框架特定指南

[Jupyter notebook 支持](jupyter-notebook-support.html)

