7

I am using the IPython module in a Jupyter Notebook. I am using the display module to display buttons.

from ipywidgets import widgets
import IPython.display as dsply
def click_reset(b):
    print("reset domains button")
    restoreDomains()

resetButton = widgets.Button(description="Reset Domains")
resetButton.on_click(click_reset)
dsply.display(resetButton)

This works fine, but I am trying to find a way to programatically hide certain buttons. Based off the execution of my other code, I want certain buttons to be removed from the UI. Is there anything like hide(resetButton) that I can use?

GreySage
  • 1,153
  • 19
  • 39

3 Answers3

9

You can hide a widget using

resetButton.layout.visibility = 'hidden'

to let the widget still consume space, or

resetButton.layout.display = 'none'

to let the widget not consume space anymore.

The top-level attribute resetButton.visible = False is not longer supported.

Jan Martin Keil
  • 1,276
  • 9
  • 9
  • To make the item visible again use `resetButton.layout.visibility = 'visible'` or `resetButton.progress_bar.layout.display = None` (Yes, that#s quite confusing.) – jonas37 Mar 02 '22 at 15:30
7

When I use @SergeyGornostaev's answer, I still have a residual cross showing up on the left side of the cell output. I found the following command removes the widget all together:

resetButton.close()
Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
2

You can hide every widget by setting it's property visible to False

resetButton.visible = False
Sergey Gornostaev
  • 7,596
  • 3
  • 27
  • 39