File tree 1 file changed +6
-2
lines changed 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 25
25
26
26
canvas = FigureCanvasTkAgg (fig , master = root ) # A tk.DrawingArea.
27
27
canvas .draw ()
28
- canvas .get_tk_widget ().pack (side = tkinter .TOP , fill = tkinter .BOTH , expand = 1 )
29
28
30
29
toolbar = NavigationToolbar2Tk (canvas , root )
31
30
toolbar .update ()
32
- canvas .get_tk_widget ().pack (side = tkinter .TOP , fill = tkinter .BOTH , expand = 1 )
33
31
34
32
35
33
def on_key_press (event ):
@@ -40,6 +38,12 @@ def on_key_press(event):
40
38
canvas .mpl_connect ("key_press_event" , on_key_press )
41
39
42
40
button = tkinter .Button (master = root , text = "Quit" , command = root .quit )
41
+
42
+ # Packing order is important. Widgets are processed sequentially and if there
43
+ # is no space left, because the window is too small, they are not displayed.
44
+ # The canvas is rather flexible in its size, so we pack it last which makes
45
+ # sure the UI controls are displayed as long as possible.
43
46
button .pack (side = tkinter .BOTTOM )
47
+ canvas .get_tk_widget ().pack (side = tkinter .TOP , fill = tkinter .BOTH , expand = 1 )
44
48
45
49
tkinter .mainloop ()
You can’t perform that action at this time.
0 commit comments