pyvista.Plotter.add_slider_widget#

Plotter.add_slider_widget(callback, rng, value=None, title=None, pointa=(0.4, 0.9), pointb=(0.9, 0.9), color=None, pass_widget=False, interaction_event='end', style=None, title_height=0.03, title_opacity=1.0, title_color=None, fmt=None, slider_width=None, tube_width=None)[source]#

Add a slider bar widget.

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

Parameters:
callbackcallable()

Called every time the slider is updated. This should take a single parameter: the float value of the slider. If pass_widget=True, callable should take two parameters: the float value of the slider and the widget itself.

rngtuple(float)

Length two tuple of the minimum and maximum ranges of the slider.

valuefloat, optional

The starting value of the slider.

titlestr, optional

The string label of the slider widget.

pointatuple(float), optional

The relative coordinates of the left point of the slider on the display port.

pointbtuple(float), optional

The relative coordinates of the right point of the slider on the display port.

colorColorLike, optional

Either a string, RGB list, or hex color string. Defaults to pyvista.global_theme.font.color.

pass_widgetbool, optional

If True, the widget will be passed as the last argument of the callback.

interaction_eventvtk.vtkCommand.EventIds, str, optional

The VTK interaction event to use for triggering the callback. Accepts either the strings 'start', 'end', 'always' or a vtk.vtkCommand.EventIds.

Changed in version 0.38.0: Changed from event_type to interaction_event and now accepts either strings or vtk.vtkCommand.EventIds.

stylestr, optional

The name of the slider style. The list of available styles are in pyvista.global_theme.slider_styles. Defaults to None.

title_heightfloat, optional

Relative height of the title as compared to the length of the slider.

title_opacityfloat, optional

Opacity of title. Defaults to 1.0.

title_colorColorLike, optional

Either a string, RGB sequence, or hex color string. Defaults to the value given in color.

fmtstr, optional

String formatter used to format numerical data. Defaults to None.

slider_widthfloat, optional

Normalized width of the slider. Defaults to the theme’s slider width.

tube_widthfloat, optional

Normalized width of the tube. Defaults to the theme’s tube width.

Returns:
vtk.vtkSliderWidget

Slider widget.

Examples

>>> import pyvista as pv
>>> pl = pv.Plotter()
>>> def create_mesh(value):
...     res = int(value)
...     sphere = pv.Sphere(
...         phi_resolution=res, theta_resolution=res
...     )
...     pl.add_mesh(sphere, name="sphere", show_edges=True)
...
>>> slider = pl.add_slider_widget(
...     create_mesh,
...     [5, 100],
...     title="Resolution",
...     title_opacity=0.5,
...     title_color="red",
...     fmt="%0.9f",
...     title_height=0.08,
... )
>>> pl.show()
https://d33wubrfki0l68.cloudfront.net/4ee0c28f3fd6a89aed5a1ac1d53639d962514802/198cf/_images/pyvista-plotter-add_slider_widget-1_00_00.png