1

I am using matplotlib with tk/tkinter, following the "Embedding in Tk"

self._figure = Figure()
self._axes: matplotlib.axes.Axes = self._figure.add_subplot(111)
self._canvas = FigureCanvasTkAgg(self._figure, master=frame)

toolbar = NavigationToolbar2Tk(self._canvas, frame)
toolbar.update()

According to Tool Manager

self._figure.canvas.manager.toolmanager.remove_tool("pan")

should work, but it does not.

# self._figure.canvas does not have attribute 'manager'

As one can see in the screenshot from vs-code, FigureCanvasTkAgg does not have attribute 'manager':

enter image description here

How can I access the toolmanager?

Martin Meeser
  • 2,784
  • 2
  • 28
  • 41
  • It seems to me that when the figure is embedded in a tkinter window, the FigureManager is not used and as a consequence, the figure does not have a ToolManager as well. So you cannot access it. I think you need to directly modify the `NavigationToolbar2Tk` like in https://stackoverflow.com/questions/59155873/how-to-remove-toolbar-button-from-navigationtoolbar2tk-figurecanvastkagg, https://stackoverflow.com/questions/55779944/how-to-remove-toolbar-buttons-from-matplotlib – j_4321 Jun 25 '20 at 08:49
  • but i want to have my own toggletool but I will take a look at NavigationToolbar2Tk – Martin Meeser Jun 25 '20 at 11:42
  • You can look at matplotlib's code to figure out when they create the ToolManager (I guess it is when the backend is initialized) and try to adapt it for your code. Or you can write your own toggletool() function for `NavigationToolbar2Tk`. – j_4321 Jun 25 '20 at 11:45

0 Answers0