I want to display IPython.display.HTML object i.e. html_bt and widget i.e. bt inside HBox Layout. How do I achieve that? Is it even possible? Or how do I convert html_bt to widget objects? Following is my code:
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
ipywidgets has its own HTML widget, if you use that does it give what you want?
from ipywidgets import widgets, Layout, HBox, HTML
# 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, html_bt])
h_box
One slightly long-winded fix for this is to display your IPython.display.HTML in a ipywidgets.widgets.Output panel and provide that to the HBox.
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)
)
html_out = widgets.Output()
with html_out:
display(html_bt)
h_box = HBox([bt, html_out])
h_box
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With