| 218 | |
| 219 | @_isolated_tk_test(success_count=1) |
| 220 | def test_canvas_focus(): |
| 221 | import tkinter as tk |
| 222 | import matplotlib.pyplot as plt |
| 223 | success = [] |
| 224 | |
| 225 | def check_focus(): |
| 226 | tkcanvas = fig.canvas.get_tk_widget() |
| 227 | # Give the plot window time to appear |
| 228 | if not tkcanvas.winfo_viewable(): |
| 229 | tkcanvas.wait_visibility() |
| 230 | # Make sure the canvas has the focus, so that it's able to receive |
| 231 | # keyboard events. |
| 232 | if tkcanvas.focus_lastfor() == tkcanvas: |
| 233 | success.append(True) |
| 234 | plt.close() |
| 235 | root.destroy() |
| 236 | |
| 237 | root = tk.Tk() |
| 238 | fig = plt.figure() |
| 239 | plt.plot([1, 2, 3]) |
| 240 | root.after(0, plt.show) |
| 241 | root.after(100, check_focus) |
| 242 | root.mainloop() |
| 243 | |
| 244 | if success: |
| 245 | print("success") |
| 246 | |
| 247 | |
| 248 | @_isolated_tk_test(success_count=2) |