Widget Button to open url

This is because the notebook does not know where to display the Javascript object, so instead it logs it in the console to let you know that something is amiss. One solution would be to point your display to a specific Output:

import ipywidgets as widgets
from IPython.display import display, Javascript

out = widgets.Output()


def window_open_button(url):
    with out:
        display(Javascript(f'window.open("{url.tooltip}");'))


ss = widgets.Button(description="hello", tooltip='https://www.google.com')
ss.on_click(window_open_button)

with out:
    display(ss)
out
3 Likes