1

First time posting, but have found these forums incredibly helpful with my python learning!

I have a problem when I call plt.plot as it's resizing my tkinter window. I've tried this in python 2.7 and 3.5 both seem to have the issue.

Below is just some sample code to re-create the problem. You don't even need to show the graph for this problem to be re-created as soon as you plot the data it resizes.

Before

After

from tkinter import *
import matplotlib.pyplot as plt

x = [1,2,3,4,5]
master = Tk() 
def plotting():
    plt.plot(x)
    #plt.show()



master.minsize(width=450, height=600)
master.wm_title("Tester")

#
y = Button(master, text='START', command=plotting )
y.place(x=230, y=180)

master.mainloop()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Gardener85
  • 369
  • 1
  • 9
  • Did you try using `master.resizable(width=False, height=False)` ? – RPT May 01 '17 at 13:45
  • The size of the Tkinter window doesn't seem to change for me. It remains the same even without setting `resizable` to `False` – RPT May 01 '17 at 13:50
  • @R.p.T I just tried master.resizable(width=False, height=False), but still no luck. – Gardener85 May 01 '17 at 13:53
  • I'm using windows 10 and my laptop resolution is 1920*1080 if those details help anyone solve this – Gardener85 May 01 '17 at 13:55
  • That's weird. Try disabling the grid_propagate and see if it works. Do, `master.grid_propagate(0)` – RPT May 01 '17 at 13:58
  • Ok what I noticed in the images you provided was the `before` image had the Tkinter title `Tester` and the `after` image does not have the title. Are you sure you are using the same code you have provided here? – RPT May 01 '17 at 14:00
  • @R.p.T Just tried master.grid_propagate(0) but still the same. Yes I noticed that too, so I ran the code again and if you wait a few seconds the title comes back correctly after a short delay. When I took the screen shot I must have been too quick. – Gardener85 May 01 '17 at 14:04
  • Honestly, I don't think there is anything wrong with this code you have provided here. It works perfectly fine like it should. – RPT May 01 '17 at 14:05
  • Granted I'm no expert, but I think I read somewhere that pyplot is also using tkinter. I know from some other programs I've written that pyplot uses some default DPI's. I'm wondering now if it's changing the DPI and thus the resolution of my 'tester' window. – Gardener85 May 01 '17 at 14:07
  • Is there a way I can take a look at your actual code to see where the error might be? I'm guessing the code you provided here is only an example code that focuses on the problem you are facing(?). Because I cannot think of any reason why it would resize your window – RPT May 01 '17 at 14:24
  • @R.p.T I think I found the problem. I was going to ask you to try re-creating my display settings then I noticed I had the following set: – Gardener85 May 01 '17 at 14:33
  • "Change the size of text, apps and other items: 150% (Recommended)" When I changed that to 100% the tkinter window didn't resize on me anymore – Gardener85 May 01 '17 at 14:34
  • Ok that was not a problem with the code, but you might want to post the answer anyway just in case someone else ends up with the same *problem in the future. – RPT May 01 '17 at 14:38
  • Is there any solution for it with using %150 scaling. It may be bug for tkinter or matplotlib. – Halil İbrahim Oymacı Feb 06 '20 at 06:55

2 Answers2

1

Under windows customize display there's a scrollbar for: "Change the size of text, apps and other items: 150% (Recommended)"

When I changed that to 100% the tkinter window no longer resizes.

Thank you @R.p.T for trying to assist me!

Gardener85
  • 369
  • 1
  • 9
0

In stead of using plt.plot(x), you might want to use plt.Figure() first. To be more specific, plotting() function can be constructed as follows.

def plotting():
    fig = plt.Figure()
    ax = fig.add_subplot()
    ax.plot(x)

Then, you can work on fig to realize the functions.

Ricardo
  • 691
  • 3
  • 11