Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9cea8ea

Browse filesBrowse files
jmehneImportanceOfBeingErnest
authored andcommitted
Embedding in Tk example: Fix toolbar being clipped. (#15266)
Calling `pack` without options puts the widget at the end of the package list. Space is allocated to widgets sequentially. If a window is too small, there may be no space left for widgets. By packing the canvas last, we essentially give the toolbar and the quit button priority in the packing order. Fixes #13485.
1 parent 2aba5aa commit 9cea8ea
Copy full SHA for 9cea8ea

File tree

Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-2
lines changed

‎examples/user_interfaces/embedding_in_tk_sgskip.py

Copy file name to clipboardExpand all lines: examples/user_interfaces/embedding_in_tk_sgskip.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525

2626
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
2727
canvas.draw()
28-
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
2928

3029
toolbar = NavigationToolbar2Tk(canvas, root)
3130
toolbar.update()
32-
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
3331

3432

3533
def on_key_press(event):
@@ -40,6 +38,12 @@ def on_key_press(event):
4038
canvas.mpl_connect("key_press_event", on_key_press)
4139

4240
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.
4346
button.pack(side=tkinter.BOTTOM)
47+
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
4448

4549
tkinter.mainloop()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.