@@ -491,6 +491,29 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
491491 # Avoid using self.window (prefer self.canvas.get_tk_widget().master),
492492 # so that Tool implementations can reuse the methods.
493493 self .window = window
494+
495+ tk .Frame .__init__ (self , master = window , borderwidth = 2 ,
496+ width = int (canvas .figure .bbox .width ), height = 50 )
497+
498+ self ._buttons = {}
499+ for text , tooltip_text , image_file , callback in self .toolitems :
500+ if text is None :
501+ # Add a spacer; return value is unused.
502+ self ._Spacer ()
503+ else :
504+ self ._buttons [text ] = button = self ._Button (
505+ text ,
506+ str (cbook ._get_data_path (f"images/{ image_file } .gif" )),
507+ toggle = callback in ["zoom" , "pan" ],
508+ command = getattr (self , callback ),
509+ )
510+ if tooltip_text is not None :
511+ ToolTip .createToolTip (button , tooltip_text )
512+
513+ self .message = tk .StringVar (master = self )
514+ self ._message_label = tk .Label (master = self , textvariable = self .message )
515+ self ._message_label .pack (side = tk .RIGHT )
516+
494517 NavigationToolbar2 .__init__ (self , canvas )
495518 if pack_toolbar :
496519 self .pack (side = tk .BOTTOM , fill = tk .X )
@@ -547,51 +570,6 @@ def _Spacer(self):
547570 s .pack (side = tk .LEFT , padx = 5 )
548571 return s
549572
550- def _init_toolbar (self ):
551- xmin , xmax = self .canvas .figure .bbox .intervalx
552- height , width = 50 , xmax - xmin
553- tk .Frame .__init__ (self , master = self .window ,
554- width = int (width ), height = int (height ),
555- borderwidth = 2 )
556-
557- self .update () # Make axes menu
558-
559- self ._buttons = {}
560- for text , tooltip_text , image_file , callback in self .toolitems :
561- if text is None :
562- # Add a spacer; return value is unused.
563- self ._Spacer ()
564- else :
565- self ._buttons [text ] = button = self ._Button (
566- text ,
567- str (cbook ._get_data_path (f"images/{ image_file } .gif" )),
568- toggle = callback in ["zoom" , "pan" ],
569- command = getattr (self , callback ),
570- )
571- if tooltip_text is not None :
572- ToolTip .createToolTip (button , tooltip_text )
573-
574- self .message = tk .StringVar (master = self )
575- self ._message_label = tk .Label (master = self , textvariable = self .message )
576- self ._message_label .pack (side = tk .RIGHT )
577-
578- def _update_buttons_checked (self ):
579- for name , mode in [("Pan" , "PAN" ), ("Zoom" , "ZOOM" )]:
580- button = self ._buttons .get (name )
581- if button :
582- if self .mode .name == mode and not button .var .get ():
583- button .select ()
584- elif self .mode .name != mode and button .var .get ():
585- button .deselect ()
586-
587- def pan (self , * args ):
588- super ().pan (* args )
589- self ._update_buttons_checked ()
590-
591- def zoom (self , * args ):
592- super ().zoom (* args )
593- self ._update_buttons_checked ()
594-
595573 def configure_subplots (self ):
596574 toolfig = Figure (figsize = (6 , 3 ))
597575 window = tk .Toplevel ()
0 commit comments