Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Milestone
Description
Bug report
Bug summary
I am using embedded plots in a TKinter application. In theFigureCanvasTkAgg.__init__
method, at the end there is a call to focus_set, stealing focus upon construction of the widget. To make matters worse, focus stealing happens asynchronous.
Code for reproduction
importtkinterastkfrommatplotlib.figureimportFigurefrommatplotlib.backends.backend_tkaggimportFigureCanvasTkAggt=tk.Tk()b1=tk.Button(t,text='My Button')b1.pack(side='top')f=Figure()fc=FigureCanvasTkAgg(f,t)fc.get_tk_widget().pack()# !! after FigureCanvasTkAgg initialization !!b1.focus_set()t.after(500,lambda:print(t.focus_get()))t.mainloop()
Actual outcome
C:\TEMP>python tkagg.py.!canvas
I.e. canvas has focus although button should have it.
Expected outcome
- Creating a widget of any kind should never steal focus.
- Using focus_set() afterwards should be able to reset focus.
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: 2.0.2
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.6.2
- Jupyter version (if applicable):
- Other libraries:
Python installed via official installer, matplotlib via pip.
The call tofocus_set
is still present in the master version:
self._tkcanvas.focus_set() |