小编Vai*_*gre的帖子

在 ipywidgets 中显示 IPython.display.HTML 类对象

我想在 HBox 布局内显示 IPython.display.HTML 对象(即 html_bt)和小部件(即 bt)。我该如何实现这一目标?有可能吗?或者如何将 html_bt 转换为小部件对象?以下是我的代码:

from ipywidgets import widgets, Layout, HBox
from IPython.display import display, HTML

css_str = '<style>.foo{color:#F00;} )} </style>'


out = widgets.Output()

def OnClick():
    with out:
        print('QQQ')

html_bt=HTML(css_str + '<button class="button-style" onclick="IPython.notebook.kernel.execute(\'OnClick()\')"> <img src="https://www.fnordware.com/superpng/pnggrad16rgb.png" alt="Snow"></button>')

bt = widgets.Button(
    description='Click me',
    disabled=False,
    button_style='', # 'success', 'info', 'warning', 'danger' or ''
    tooltip='Click me',
    icon='check' # (FontAwesome names without the `fa-` prefix)
)


h_box = HBox([bt, display(html_bt)])
h_box
Run Code Online (Sandbox Code Playgroud)

ipython jupyter-notebook ipywidgets

5
推荐指数
1
解决办法
4899
查看次数

标签 统计

ipython ×1

ipywidgets ×1

jupyter-notebook ×1