matplotlib.widgets._Buttons#

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

Bases:AxesWidget

The base class forCheckButtons andRadioButtons.

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 consideredpublic on the subclasses.

disconnect(cid)[source]#

Remove the observer with connection idcid.

on_clicked(func)[source]#

Connect the callback functionfunc to button click events.

Parameters:
funccallable

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

deffunc(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 theText labels.

Added in version 3.7.

Parameters:
propsdict

Dictionary ofText properties to be used for the labels. Sameformat as label_props argument ofRadioButtons orCheckButtons.

Examples usingmatplotlib.widgets._Buttons#

Check buttons

Check buttons

Radio Buttons

Radio Buttons

Radio Buttons Grid

Radio Buttons Grid