Phenomenon:
print statement not work in JupyterLab(can not see any output), but work in Jupyter NotebookEnvironment:
Code:
from IPython.display import display
from ipywidgets import widgets
button = widgets.Button(description="Click Me!")
display(button)
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
I'm also running into the same problem, similar environment.
You'll need to use the output capturing mechanism in ipywidgets:
from IPython.display import display
from ipywidgets import widgets
button = widgets.Button(description="Click Me!")
display(button)
output = widgets.Output()
@output.capture()
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
display(output)
Another advantage of this method is that it lets you put that output where you want, not just in that cell.
I remember there is jupyter document describing the necessity for such breaking change, but google doesn't help me...
Since this is a landing-issue, @jasongrout can you provide some architectural link on what is going?
https://github.com/jupyterlab/jupyterlab/issues/3151#issuecomment-339476572 and https://github.com/jupyterlab/jupyterlab/issues/1254 give some more context on this.
Closing as answered.
@jasongrout, can @output.capture be used inside a class? And how or where do you place this?
@jasongrout, can @output.capture be used inside a class? And how or where do you place this?
Stumbled across this. Here is a naive way...
```import ipywidgets as widgets
from IPython.display import display
class ExampleButton(widgets.Button):
output = widgets.Output()
@output.capture()
def on_button_clicked(b):
print("Button clicked.")
button = ExampleButton(description="Click Me!")
display(button)
button.on_click(ExampleButton.on_button_clicked)
display(ExampleButton.output)
Most helpful comment
You'll need to use the output capturing mechanism in ipywidgets: