Skip to content
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

tk window immediately resizes down to zero-height upon showing up. #16926

Closed
anntzer opened this issue Mar 26, 2020 · 6 comments · Fixed by #16929
Closed

tk window immediately resizes down to zero-height upon showing up. #16926

anntzer opened this issue Mar 26, 2020 · 6 comments · Fixed by #16929
Labels
GUI: tk Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Mar 26, 2020

Bug report

Bug summary

tk window (whether tkagg or mplcairo.tk) immediately resizes down to zero-height upon showing up.

Code for reproduction

$ MPLBACKEND=tkagg python -c "from pylab import *; plot(); show()"

Actual outcome

As described above.

Expected outcome

Window stays at original size.

Matplotlib version

  • Operating system: arch linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): tkany
  • Python version: 38
  • Jupyter version (if applicable):
  • Other libraries:

This bisects to #16828 (attn @QuLogic), even though it's not clear how that's related... perhaps the dynamic changes to figure dpi confuse tk, but it's not clear why this is different from before?

@anntzer anntzer added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. GUI: tk labels Mar 26, 2020
@anntzer anntzer added this to the v3.3.0 milestone Mar 26, 2020
@anntzer anntzer changed the title tkagg tk window immediately resizes down to zero-height upon showing up. Mar 26, 2020
@QuLogic
Copy link
Member

QuLogic commented Mar 27, 2020

I'm guessing this is related to the flaky test on AppVeyor. The only thing that's hit by that test is the fix to Text.get_window_extent: https://github.com/matplotlib/matplotlib/pull/16828/files#diff-15e8fbe2a4d40deb738e8627eba02318L894

My best guess is that figure.dpi has never been correctly set, and it's been relying on this accidental change to do so.

@QuLogic
Copy link
Member

QuLogic commented Mar 27, 2020

So it seems that's not it, as I can never trigger a case where dpi is not None, but self.figure.dpi is None (or something other than dpi). The strange thing is that if I print out all the properties that would be changed in Figure._set_dpi, nothing changes. So neither the forward call to Figure.set_size_inches (which might hit the canvas/toolbar size), nor the callbacks for the dpi_changed event do this. Yet somehow on a later call, the size is smaller...

There's definitely something else weird going on; if you add an extra dpi changed on the old code:

MPLBACKEND=tkagg python -c "from pylab import *; plot(); gcf().dpi=100; show()"

then there will be one call to Figure.set_size_inches with [6.4 4.46], but it magically fixes itself. I'm guessing what happens is that since the dpi change in the Text.get_window_extent is part of the draw/stale mechanism, it is enough to propagate that height change.

@FBIShowYourHand
Copy link

a question about how to use Chinese,when I want to show Chinese,it always shows me errors,thanks

QuLogic added a commit to QuLogic/matplotlib that referenced this issue Mar 27, 2020
Resizing the figure directly does not account for the toolbar, so
figures are actually a little shorter than they should be. The recent
change to `Text.get_window_extent` some how causes this to actually get
reflected in the Matplotlib figure size, which cycles back to Tk and
shrinks the window. However, this can be triggered by other calls to
`Figure.set_size_inches` as noted in the fixed issues.

Fixes matplotlib#10083.
Fixes matplotlib#10566.
Fixes matplotlib#16926.
@QuLogic QuLogic modified the milestones: v3.3.0, v3.2.2 Mar 27, 2020
@tacaswell
Copy link
Member

was #16828 backported to the v3.2.x branch?

@tacaswell
Copy link
Member

Ah, I understand now, not a regression on 3.2.x, but was backported there because it fixed some other bugs.

@QuLogic
Copy link
Member

QuLogic commented Mar 28, 2020

You're right though; this bug was never in 3.2, so this issue shouldn't be tagged on it.

@QuLogic QuLogic modified the milestones: v3.2.2, v3.3.0 Mar 28, 2020
toddrjen pushed a commit to toddrjen/matplotlib that referenced this issue Apr 6, 2020
Resizing the figure directly does not account for the toolbar, so
figures are actually a little shorter than they should be. The recent
change to `Text.get_window_extent` some how causes this to actually get
reflected in the Matplotlib figure size, which cycles back to Tk and
shrinks the window. However, this can be triggered by other calls to
`Figure.set_size_inches` as noted in the fixed issues.

Fixes matplotlib#10083.
Fixes matplotlib#10566.
Fixes matplotlib#16926.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: tk Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants