ipywidgets: Cannot create a widget whose initial state is visible=False

In ipywidgets 5.2.2 the code below produces a widget that is visible:

check = Checkbox(description="A box", visible=False)
check

In ipywidgets 4, the checkbox wouldn’t be displayed until I later set check.visible = True.

While this minimal example is pretty silly, I do rely heavily on being able to construct a widget with some components not visible until the user interacts with other elements.

A workaround or fix would be great.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 25 (18 by maintainers)

Most upvoted comments

Both title and select use the same instance of Layout, and both widgets are used twice (it shows the same Label and SelectMultiple twice, not copies). In short, all the (non-box) widgets have the exact same instance of box_layout. Try creating one layout for each widget (and probably multiple value widgets).

Can you post some code reproducing this?

You can also use layout.display='none' to hide the widget.

Closing as fixed in master and will be in 6.0.

@SylvainCorlay – I’d suggest two things (both of which may be impractical, I’m really not familiar with the codebase):

  1. The .visible attribute should accurately reflect whether the widget is visible. Right now setting .visibility='hidden' leaves visible set to True.
  2. If a user sets visible=False in the function call then I’d expect something like this in the constructor:
visible = kwd.pop('visible', True)
if visible:
     some_widget.layout.visibility = 'visible'
else:
     some_widget.layout.visibility = 'hidden'

It is unfortunate that DeprecationWarnings get hidden by default…

This example also doesn’t generate an invisible checkbox:

check = Checkbox(description="A box", visibility='hidden')
check

@hainm – looks like setting visibility to 'visible' brings it back.