Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee16b6c

Browse files
committed
Avoid possible exception when toggling full-screen
In `examples/user_interfaces/embedding_in_tk.py`, a FigureCanvasTkAgg is embedded into a Tkinter window and the default mpl key bindings are implemented with matplotlib.backend_bases.key_press_handler. If the user attempts to toggle full-screen mode by pressing 'f', an AttributeError is raised because the FigureCanvasTkAgg has no 'manager' attribute. Indeed, since pyplot is not being used, no FigureManagerTkAgg object gets created. One fix is to check for the 'manager' attribute and do nothing if it doesn't exist. (This is what is done in FigureCanvasBase.get_window_title/set_window_title, for example.)
1 parent 263c06a commit ee16b6c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,8 @@ def key_press_handler(event, canvas, toolbar=None):
24792479

24802480
# toggle fullscreen mode (default key 'f')
24812481
if event.key in fullscreen_keys:
2482-
canvas.manager.full_screen_toggle()
2482+
if hasattr(canvas, 'manager'):
2483+
canvas.manager.full_screen_toggle()
24832484

24842485
# quit the figure (defaut key 'ctrl+w')
24852486
if event.key in quit_keys:

0 commit comments

Comments
 (0)