Jupyter Notebook 中 javascript 和 python 之间的通信

Sid*_*dML 7 javascript python jupyter-notebook

javascript = """
<script type="text/Javascript">

   function exec_code(){
       var res = confirm("Hello");
       var kernel = IPython.notebook.kernel;
       console.log("show:" + res);
       var callbacks = {
         iopub : {
         output : res,
    }
    }
   IPython.notebook.kernel.execute(res, callbacks);
   }
   exec_code();
</script>
"""

HTML(javascript)
Run Code Online (Sandbox Code Playgroud)

我想在 javascript 中有一个确认弹出窗口,并根据用户是否执行“确定”或“取消”,将值存储在变量 res 中。然后我想将其暴露给 jupyter 笔记本中同一单元格中的 python。我尝试了callbacks.iopub.output,但似乎不起作用。

我想做一个 print( output ) 来显示 res 中的值——true 或 false。