pyvista.plotting.widgets.WidgetHelper.add_radio_button_widget

pyvista.plotting.widgets.WidgetHelper.add_radio_button_widget#

WidgetHelper.add_radio_button_widget(
callback,
radio_button_group,
value=False,
title=None,
position=(10.0, 10.0),
size=50,
border_size=8,
color_on='blue',
color_off='grey',
background_color=None,
)[source]#

Add a radio button widget to the scene.

Radio buttons work in groups. Only one button in a group can be on at at the same time. Typically you should add two or more buttons belonging to a same radio button group. Each button should be passed a callback function. This function will be called when a radio button in a group is switched on, assuming it was not already on.

Parameters:
callbackcallable()

The method called when a radio button’s state changes from off to on.

radio_button_group: str

Name of the group for the radio button.

valuebool, default: False

The default state of the button. If multiple buttons in the same group are initialized with to True state, only the last initialized button will remain on.

title: str, optional

String title to be displayed next to the radio button.

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

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

sizeint, default: 50

The diameter of the button in number of pixels.

border_sizeint, default: 8

The size of the borders of the button in pixels.

color_onColorLike, default: 'blue'

The color used when the button is checked.

color_offColorLike, default: 'grey'

The color used when the button is not checked.

background_colorColorLike, optional

The background color of the button. If not set, default will be set as self.background_color.

Returns:
vtk.vtkButtonWidget

The VTK button widget configured as a radio button.

Examples

The following example creates a background color switcher.

>>> import pyvista as pv
>>> p = pv.Plotter()
>>> def set_bg(color):
...     def wrapped_callback():
...         p.background_color = color
...
...     return wrapped_callback
...
>>> _ = p.add_radio_button_widget(
...     set_bg('white'),
...     'bgcolor',
...     position=(10.0, 200.0),
...     title='White',
...     value=True,
... )
>>> _ = p.add_radio_button_widget(
...     set_bg('lightblue'),
...     'bgcolor',
...     position=(10.0, 140.0),
...     title='Light Blue',
... )
>>> _ = p.add_radio_button_widget(
...     set_bg('pink'),
...     'bgcolor',
...     position=(10.0, 80.0),
...     title='Pink',
... )
>>> p.show()
../../../_images/pyvista-plotting-widgets-WidgetHelper-add_radio_button_widget-1_00_00.png