pyvista.Plotter.add_checkbox_button_widget#

Plotter.add_checkbox_button_widget(
callback,
value=False,
position=(10.0, 10.0),
size=50,
border_size=5,
color_on='blue',
color_off='grey',
background_color='white',
)[source]#

Add a checkbox button widget to the scene.

This is useless without a callback function. You can pass a callable function that takes a single argument, the state of this button widget and performs a task with that value.

Parameters:
callbackcallable()

The method called every time the button is clicked. This should take a single parameter: the bool value of the button.

valuebool, default: False

The default state of the button.

positionsequence[float], default: (10.0, 10.0)

The absolute coordinates of the bottom left point of the button.

sizeint, default: 50

The size of the button in number of pixels.

border_sizeint, default: 5

The size of the borders of the button in pixels.

color_onColorLike, optional

The color used when the button is checked. Default is 'blue'.

color_offColorLike, optional

The color used when the button is not checked. Default is 'grey'.

background_colorColorLike, optional

The background color of the button. Default is 'white'.

Returns:
vtk.vtkButtonWidget

The VTK button widget configured as a checkbox button.

Examples

The following example generates a static image of the widget.

>>> import pyvista as pv
>>> mesh = pv.Sphere()
>>> p = pv.Plotter()
>>> actor = p.add_mesh(mesh)
>>> def toggle_vis(flag):
...     actor.SetVisibility(flag)
...
>>> _ = p.add_checkbox_button_widget(toggle_vis, value=True)
>>> p.show()
../../../_images/pyvista-Plotter-add_checkbox_button_widget-1_00_00.png

Download the interactive example at Checkbox Widget.