Plotter.add_radio_button_widget

Plotter.add_radio_button_widget#

Plotter.add_radio_button_widget(
callback,
radio_button_group,
value: bool = 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 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_groupstr

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.

titlestr, 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._plotter.background_color.

Returns:
vtkButtonWidget

The VTK button widget configured as a radio button.

Examples#

Download Python source code | Download Jupyter notebook

The following example creates a background color switcher.

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