question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

print statement of ipywidgets not work in JupyterLab

See original GitHub issue

Phenomenon:

  • print statement not work in JupyterLab(can not see any output), but work in Jupyter Notebook

Environment:

  • Ubuntu 16.04
  • Chrome v66
  • JupyterLab 0.32.1
  • Python 3.6.5

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)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
jasongroutcommented, May 17, 2018

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

why cannot I print in jupyter lab using ipywidgets class?
If I run this code from Jupyter Notebook, everything works fine, the msg is printed after the btn cell output. If I do...
Read more >
Installation — Jupyter Widgets 7.6.5 documentation
Answer: A text representation of the widget is printed if the widget control is not available. It may mean the widget JavaScript is...
Read more >
3.3. Mastering widgets in the Jupyter Notebook
The ebook and printed book are available for purchase at Packt Publishing. ... This is useful with long-lasting computations that should not run...
Read more >
How to use ipywidgets to make your Jupyter notebook ...
Jupyter widgets can make notebooks be more interactive and make data exploration much easier, especially for end users who are not coders.
Read more >
Ipywidgets with matplotlib - Kapernikov
The say_my_name function below prints the text 'my name is {name}'. ... Sometimes, not all arguments need to be linked to the widget....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found