@@ -507,17 +507,23 @@ class NavigationToolbar2Tk(NavigationToolbar2, tk.Frame):
507
507
Attributes
508
508
----------
509
509
canvas : `FigureCanvas`
510
- the figure canvas on which to operate
510
+ The figure canvas on which to operate.
511
511
win : tk.Window
512
- the tk.Window which owns this toolbar
513
-
512
+ The tk.Window which owns this toolbar.
513
+ pack_toolbar : bool, default: True
514
+ If True, add the toolbar to the parent's pack manager's packing list
515
+ during initialization with ``side='bottom'`` and ``fill='x'``.
516
+ If you want to use the toolbar with a different layout manager, use
517
+ ``pack_toolbar=False``.
514
518
"""
515
- def __init__ (self , canvas , window ):
519
+ def __init__ (self , canvas , window , * , pack_toolbar = True ):
516
520
self .canvas = canvas
517
521
# Avoid using self.window (prefer self.canvas.get_tk_widget().master),
518
522
# so that Tool implementations can reuse the methods.
519
523
self .window = window
520
524
NavigationToolbar2 .__init__ (self , canvas )
525
+ if pack_toolbar :
526
+ self .pack (side = tk .BOTTOM , fill = tk .X )
521
527
522
528
def destroy (self , * args ):
523
529
del self .message
@@ -582,7 +588,6 @@ def _init_toolbar(self):
582
588
self .message = tk .StringVar (master = self )
583
589
self ._message_label = tk .Label (master = self , textvariable = self .message )
584
590
self ._message_label .pack (side = tk .RIGHT )
585
- self .pack (side = tk .BOTTOM , fill = tk .X )
586
591
587
592
def configure_subplots (self ):
588
593
toolfig = Figure (figsize = (6 , 3 ))
0 commit comments