Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Embedding in Tk example: Fix toolbar being clipped. #15266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jmehne
Copy link
Contributor

@jmehne jmehne commented Sep 14, 2019

Fixes #13485.

This was driving me crazy, but #13485 pointed me to the right code in mpl where it actually works, and it has this helpful comment there:

 # packing toolbar first, because if space is getting low, last packed
 # widget is getting shrunk first (-> the canvas)

So, the solution is to pack the canvas after the toolbar got initialized, because initializing the toolbar will call pack on the root window.

Flake 8 passes, the other points don't apply, but correct me if I'm wrong :)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@ImportanceOfBeingErnest
Copy link
Member

The tkinter.Button that comes afterwards is still meant to shrink or not?

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 matplotlib#13485.
@jmehne jmehne force-pushed the 13485-fix-clipped-toolbar branch from 335eff2 to 350c50a Compare September 15, 2019 06:52
@jmehne
Copy link
Contributor Author

jmehne commented Sep 15, 2019

Oops, didn't even notice the button.

I would argue that any UI controls should be displayed as long as possible, because the canvas is rather flexible in size.

After re-reading the tk docs: calling pack puts a widget in the package list. Space is allocated to widgets sequentially from start to end. If there is no space left to distribute, because the window is too small, no more widgets are displayed.

The question is, what is the priority of the UI controls in this example? Creating a toolbar implicitly packs it, so to keep the example simple I think it is okay if the order goes:

  • toolbar
  • quit button
  • canvas

tkinter_test

Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "embedding in tk" example is very important; for many it's the number one resource for understanding how to use matplotlib in GUIs. It's hence important to keep this example clean and working.

Thanks very much @jmehne for this update of it.

@ImportanceOfBeingErnest ImportanceOfBeingErnest merged commit 9cea8ea into matplotlib:master Sep 15, 2019
timhoffm added a commit that referenced this pull request Sep 15, 2019
…266-on-v3.2.x

Backport PR #15266 on branch v3.2.x (Embedding in Tk example: Fix toolbar being clipped.)
@jmehne jmehne deleted the 13485-fix-clipped-toolbar branch September 16, 2019 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Matplotlib NavigationToolbar2Tk disappears when reducing window size
3 participants