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.

Output widget loses some output

See original GitHub issue

I’m using version 7.4.2

import ipywidgets as widgets

output = widgets.Output()
field = widgets.Text()
updating = False

def update(change):
    global updating
    with output:
        if not updating:
            updating = True
            print('updating value')
            field.value = 'a' + change.new
            print('finished updating value')
            updating = False
            
field.observe(update, names='value')
field.value = 'b'

After running this, the Output widget only contains updating value. The text finished updating value is printed in the output area below the notebook cell.

To fix it, I can add an additional context

def update(change):
    global updating
    with output:
        if not updating:
            updating = True
            print('updating value')
            field.value = 'a' + change.new
            with output:
                print('finished updating value')
            updating = False

Here, the Output widget contains

updating value
finished updating value

as expected.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kreycommented, Mar 12, 2019

Hmm, this seems to work

@contextmanager
def output_widget_context(widget):
    if widget.msg_id == '':
        with widget:
            yield
    else:
        yield
0reactions
SylvainCorlaycommented, Jun 4, 2019

This appears to be solved in #2384. Closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

clear output of output widget plotting a Seaborn figure does ...
I would like to display in the output widget a new figure every time, i.e. totally clear the content and then add stuff...
Read more >
Output widgets: leveraging Jupyter's display system - ipywidgets
This always prints in the currently active cell, not the cell that started the background thread. This can lead to surprising behaviour in...
Read more >
Command Output in a Widget - Forum - SolarWinds THWACK
Hi all,. I was wondering if there was a way I can put a certain command's output in a widget or somehow display...
Read more >
Output Widgets - appJar
Output widgets are used for displaying information to a user. They usually provide three functions: ADD - this creates the widget; GET -...
Read more >
Event handling in Rich UI - IBM
onFocusLost occurs when the widget loses the focus. The equivalent event in JavaScript is onBlur. onKeyDown, onKeyDown occurs when the user presses any...
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