'backend independent way to (programmatically) toggle matplotlib toolbar buttons?

I am trying to find a way how to programmatically toggle the toolbar-state of a matplotlib-plot to "idle" if one of the buttons was active... I know that there are some quite old answers here https://stackoverflow.com/a/19190997/9703451 but they are specific to the NavigationToolbar2WxAgg backend, and I could not find a clear path on how to implement something like this for all the other backends such as QT5AGG, tkagg, webagg ipympl etc.

The basic setup is the following:

f, ax = plt.subplots()
  • now click on the zoom-button of the toolbar
tb = f.canvas.toolbar

# how can I "unclick" to toolbar-button programmatically?
# (ideally in a backend-independent way without fiddling around with the individual toolbar-backends...)

The reason why I want to do this is because I have a widget which acts like a "toolbar-extension", so if I click on one of the buttons of this widget, I want to reset the state of the actual toolbar.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source