matplotlib.widgets._Buttons#

class matplotlib.widgets._Buttons(ax, labels, *, useblit=True, label_props=None, layout=None, **kwargs)[source]#

Bases: AxesWidget

The base class for CheckButtons and RadioButtons.

This class provides common functionality for button widgets, such as handling click events, managing button labels, and connecting callbacks.

The class itself is private and may be changed or removed without prior warning. However, the public API it provides to subclasses is stable and considered public on the subclasses.

disconnect(cid)[source]#

Remove the observer with connection id cid.

on_clicked(func)[source]#

Connect the callback function func to button click events.

Parameters:
funccallable

When the button is clicked, call func with button label. When all buttons are cleared, call func with None. The callback func must have the signature:

def func(label: str | None) -> Any

Return values may exist, but are ignored.

Returns:
A connection id, which can be used to disconnect the callback.
set_label_props(props)[source]#

Set properties of the Text labels.

Added in version 3.7.

Parameters:
propsdict

Dictionary of Text properties to be used for the labels. Same format as label_props argument of RadioButtons or CheckButtons.

Examples using matplotlib.widgets._Buttons#

Check buttons

Check buttons

Radio Buttons

Radio Buttons

Radio Buttons Grid

Radio Buttons Grid