stopping NavigationToolbar2Tk from displaying coordinates

Viewed 550

I'm trying to get NavigationToolbar2Tk to stop printing the coordinates in red shown below. I want to stop printing becaause the window resizes when the mouse moves over the figure.

enter image description here

My code follows. Even though Frame10 has grid_propagate(False) it resizes slightly when the mouse is moved over it. I want to stop that. My code is given below.

from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg,
                                               NavigationToolbar2Tk)
from matplotlib.figure import Figure
import tkinter

root = tkinter.Tk()
root.wm_title('Stop toolbar coords')

root.grid_rowconfigure(0, weight=0)   
root.grid_rowconfigure(1, weight=0)
root.grid_rowconfigure(2, weight=0)
root.grid_columnconfigure(0, weight=0)

Frame00 = tkinter.Frame(root,width='3.0i',height='3.0i')
Frame10 = tkinter.Frame(root,width='3.0i',height='1.0i')

Frame00.grid(row=0,column=0) 
Frame00.grid_rowconfigure(0,weight=0)
Frame00.grid_columnconfigure(0,weight=0)
# stop frame from expanding to size of widget
Frame00.grid_propagate(False) 

Frame10.grid(row=1,column=0) 
Frame10.grid_rowconfigure(0,weight=0)
Frame10.grid_columnconfigure(0,weight=0)
# stop frame from expanding to size of widget
Frame10.grid_propagate(False) 

# initialize matplotlib figure
fig = Figure(figsize=(2.5,2.5),dpi=100)
ax  = fig.gca()
ax.plot([0.1,0.2,0.3],[0.5,0.6,0.7],'bo-')
ax.set_title('Title')
canvas = FigureCanvasTkAgg(fig,master=Frame00)
canvas.draw()
canvas.get_tk_widget().grid(row=0,column=0)

toolbar = NavigationToolbar2Tk(canvas,Frame10)

tkinter.mainloop()
1 Answers

The coordinates are displayed by calling the .set_message() method of the NavigationToolbar2Tk. One way to get rid of this behavior is to override this method:

class Toolbar(NavigationToolbar2Tk):

    def set_message(self, s):
        pass

# ...
toolbar = Toolbar(canvas, Frame10)
Related