【发布时间】:2020-11-13 19:58:09
【问题描述】:
我正在尝试创建一个扩展程序,将自定义按钮添加到已打开的 Jupyter Lab 笔记本的工具栏,类似于这张照片中的“提交笔记本按钮...”。我如何实现这一目标?我尝试使用以下代码,但它不起作用:
import { ToolbarButton } from "@jupyterlab/apputils";
import { DocumentRegistry } from "@jupyterlab/docregistry";
import { INotebookModel, NotebookPanel } from "@jupyterlab/notebook";
import { IDisposable } from "@lumino/disposable";
export class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
// Create the toolbar button
let mybutton = new ToolbarButton({
label: 'My Button',
onClick: () => alert('You did it!')
});
// Add the toolbar button to the notebook toolbar
panel.toolbar.insertItem(10, 'mybutton', mybutton);
// The ToolbarButton class implements `IDisposable`, so the
// button *is* the extension for the purposes of this method.
return mybutton;
}
}
【问题讨论】:
-
你找到解决办法了吗?
-
@ctwhome 在下面查看我的答案,希望对您有所帮助:stackoverflow.com/a/67693462/15206790
标签: typescript dom jupyter-notebook jupyter-lab