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)
Both
titleandselectuse the same instance ofLayout, and both widgets are used twice (it shows the sameLabelandSelectMultipletwice, not copies). In short, all the (non-box) widgets have the exact same instance ofbox_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):
.visibleattribute should accurately reflect whether the widget is visible. Right now setting.visibility='hidden'leavesvisibleset toTrue.visible=Falsein the function call then I’d expect something like this in the constructor:It is unfortunate that
DeprecationWarningsget hidden by default…This example also doesn’t generate an invisible checkbox:
@hainm – looks like setting visibility to
'visible'brings it back.