On Wed, Jul 10, 2019 at 5:00 PM Ilya Kazakevich <ilya.kazakev...@jetbrains.com> wrote: > > Hello, > > According to manual, ``clear_output`` event should clear whole cell output. > > But with the following code > > from ipywidgets import widgets > from IPython.display import clear_output > out = widgets.Output(layout={'border': '1px solid black'}) > out.append_display_data(10) > display(out) > display("20") > out.clear_output() > > only "10" is cleared, while "20" stays untouched.
The above behavior is correct, and what I would expect. The reason is because `out.clear_output()` **only** clears the output of the widget "out". The "20" that you've output has nothing to do with that output widget (the one called "out"). The "20" is simply a completely separate output. To clear everything, which is I think the behavior you expect, do this, which should work as you want: from ipywidgets import widgets from IPython.display import clear_output out = widgets.Output(layout={'border': '1px solid black'}) out.append_display_data(10) display(out) display("20") clear_output() # NOTICE: I'm calling the global clear_output function, not the clear_output method of out. -- William > > I sniffed websocket, and I see absolutely regular "clear_output" is sent. > Then, how does jupyter "understands" that only widget content must be > cleared? This is not comm message, so no connection to widget is made. > How does it work? It's because you type "out.clear_output()" instead of "clear_output()". This causes a comm message to get sent from the kernel to the widget saying "clear me". The way out.clear_output works is a bit surprising, since it involves different back and forth communication between the kernel and the frontend than you might expect. This confused me a lot when I was implementing widgets for CoCalc recently. Search for "clear_output" on this page https://github.com/jupyter-widgets/ipywidgets/issues/2385#issuecomment-484742927 for where Jason Grout clears up my confusion about how this work... -- William > > Any help (doc or source link probably) is appreciated. > > Thank you. > Ilya. > > -- > You received this message because you are subscribed to the Google Groups > "Project Jupyter" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to jupyter+unsubscr...@googlegroups.com. > To post to this group, send email to jupyter@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jupyter/11d9b97c-5827-4b48-b424-63c92c8f6de5%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- William (http://wstein.org) -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscr...@googlegroups.com. To post to this group, send email to jupyter@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CACLE5GAGZNpa6MYZW6d46dohGtpbG0nVg5vyPPwSBKy0MNv-SA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.