@@ -161,6 +161,7 @@ def _on_timer(self):
161161
162162
163163class FigureCanvasTk (FigureCanvasBase ):
164+ manager_class = FigureManagerTk
164165required_interactive_framework = "tk"
165166
166167def __init__ (self ,figure = None ,master = None ):
@@ -223,43 +224,6 @@ def _update_device_pixel_ratio(self, event=None):
223224w ,h = self .get_width_height (physical = True )
224225self ._tkcanvas .configure (width = w ,height = h )
225226
226- @classmethod
227- def new_manager (cls ,figure ,num ):
228- # docstring inherited
229- with _restore_foreground_window_at_end ():
230- if cbook ._get_running_interactive_framework ()is None :
231- cbook ._setup_new_guiapp ()
232- _c_internal_utils .Win32_SetProcessDpiAwareness_max ()
233- window = tk .Tk (className = "matplotlib" )
234- window .withdraw ()
235-
236- # Put a Matplotlib icon on the window rather than the default tk
237- # icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
238- #
239- # `ImageTk` can be replaced with `tk` whenever the minimum
240- # supported Tk version is increased to 8.6, as Tk 8.6+ natively
241- # supports PNG images.
242- icon_fname = str (cbook ._get_data_path (
243- 'images/matplotlib.png' ))
244- icon_img = ImageTk .PhotoImage (file = icon_fname ,master = window )
245-
246- icon_fname_large = str (cbook ._get_data_path (
247- 'images/matplotlib_large.png' ))
248- icon_img_large = ImageTk .PhotoImage (
249- file = icon_fname_large ,master = window )
250- try :
251- window .iconphoto (False ,icon_img_large ,icon_img )
252- except Exception as exc :
253- # log the failure (due e.g. to Tk version), but carry on
254- _log .info ('Could not load matplotlib icon: %s' ,exc )
255-
256- canvas = cls (figure ,master = window )
257- manager = FigureManagerTk (canvas ,num ,window )
258- if mpl .is_interactive ():
259- manager .show ()
260- canvas .draw_idle ()
261- return manager
262-
263227def resize (self ,event ):
264228width ,height = event .width ,event .height
265229
@@ -468,6 +432,44 @@ def __init__(self, canvas, num, window):
468432
469433self ._shown = False
470434
435+ @classmethod
436+ def create_with_canvas (cls ,canvas_class ,figure ,num ):
437+
438+ with _restore_foreground_window_at_end ():
439+ if cbook ._get_running_interactive_framework ()is None :
440+ cbook ._setup_new_guiapp ()
441+ _c_internal_utils .Win32_SetProcessDpiAwareness_max ()
442+ window = tk .Tk (className = "matplotlib" )
443+ window .withdraw ()
444+
445+ # Put a Matplotlib icon on the window rather than the default tk
446+ # icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
447+ #
448+ # `ImageTk` can be replaced with `tk` whenever the minimum
449+ # supported Tk version is increased to 8.6, as Tk 8.6+ natively
450+ # supports PNG images.
451+ icon_fname = str (cbook ._get_data_path (
452+ 'images/matplotlib.png' ))
453+ icon_img = ImageTk .PhotoImage (file = icon_fname ,master = window )
454+
455+ icon_fname_large = str (cbook ._get_data_path (
456+ 'images/matplotlib_large.png' ))
457+ icon_img_large = ImageTk .PhotoImage (
458+ file = icon_fname_large ,master = window )
459+ try :
460+ window .iconphoto (False ,icon_img_large ,icon_img )
461+ except Exception as exc :
462+ # log the failure (due e.g. to Tk version), but carry on
463+ _log .info ('Could not load matplotlib icon: %s' ,exc )
464+
465+ canvas = canvas_class (figure ,master = window )
466+ manager = FigureManagerTk (canvas ,num ,window )
467+ if mpl .is_interactive ():
468+ manager .show ()
469+ canvas .draw_idle ()
470+ return manager
471+
472+
471473def _update_window_dpi (self ,* args ):
472474newdpi = self ._window_dpi .get ()
473475self .window .call ('tk' ,'scaling' ,newdpi / 72 )