Simon
Simon

Reputation: 5698

IPython nbwidgets: Toggle Visiblity by button click

I'm using the ToggleButton and want to link it's value to the visilbiity of another widget.

I've come accross the Widget Events, but it is unclear to me how to bind the style property of the other widget to the value of the ToggleButton.

Has anyone done something similar?

Upvotes: 0

Views: 1035

Answers (1)

ac24
ac24

Reputation: 5565

I would use an observe call on the ToggleButton to change the visibility of the other widget. A simple example below.

    toggle = ipyw.ToggleButton(description='Toggle visible')
    to_hide = ipyw.IntRangeSlider(description = 'hide me')
    display(to_hide)
    display(toggle)

    def hide_slider(widg):
        if widg['new']:
            to_hide.layout.display = 'none'
        else:
            to_hide.layout.display = ''

    toggle.observe(hide_slider, names=['value'])

Upvotes: 1

Related Questions