2

I've been developing a tkinter app, which has a matplotlib graph embeded in it. The problem i am having right now is :

Allthough the functionality of the toolbar is working, it doesnt change the cursor which makes a worse user experience since you cant tell if you are zooming or not. From what i have seen from various documentation and online tutorials this shouldnt be an issue.

From what i read, the toolbar should even makes changing cursor harder, since it overrides to cursor all the time when pan or zoom is selected. I am posting the related parts of my code, please let me know if you see something that doesnt add up, or anything that i might be missing.

Any suggestion is much appriciated!

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

class Controller(tk.Tk): 
    self.canvass = FigureCanvasTkAgg(self.plots, self)
    self.canvass.show()
    self.canvass.get_tk_widget().grid(row=1, column=0, sticky="news") 

    self.toolbar_frame = tk.Frame(self, width=410, height=30)
    self.toolbar_frame.config(relief="sunken", borderwidth=1)
    self.toolbar_frame.pack_propagate(flag=False)
    self.toolbar_frame.grid(column=0, row=3, sticky="w")

    self.toolbar = NavigationToolbar2TkAgg(self.canvass, self.toolbar_frame)
    self.toolbar.pack()
    self.toolbar.update()

It turned out putting the toolbar into a frame causes that weird behavior. I just took a simple 'matplotlib in tkinter embedding' example which was working and modified it to use a frame as i did in my code, and the same problem occoured.

I need the frame because normally the toolbar uses pack and i dont want to change the whole layout just because of this, since i'have used grid all along.

1 Answer 1

2

Well I have encountered the same problem too, and oddly enough this is caused by the canvas and the toolbar not having the same master. Just making a new frame and putting the canvas and the toolbar in it will solve the problem. You still can place that frame with grid in your layout .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.