简体   繁体   English

在 tkinter 应用程序中调用 Matplotlib 会更改 Windows 上的根 window 大小

[英]Calling Matplotlib within a tkinter app changes the root window size on Windows 10

I have created a tkinter app which plots pyplot subplots on the screen (using matplotlib).我创建了一个 tkinter 应用程序,它在屏幕上绘制 pyplot 子图(使用 matplotlib)。 When testing this on a Windows 10 laptop, I am finding that as soon as the plot is created, the tkinter root window shrinks dramatically.在 Windows 10 笔记本电脑上对此进行测试时,我发现一旦创建了 plot,tkinter 根 Z045B8C742CBD962FBFAF2 就会显着缩小。

I have boiled down the issue to the following code:我将问题归结为以下代码:

import tkinter as tk
import matplotlib.pyplot as plt

def plot():
    fig, axs = plt.subplots(3, 6, sharey=True)
    print('Button pushed')
    return

root = tk.Tk()
b1 = tk.Button(root, text='Plot', command=(lambda: plot()))
b1.pack(side=tk.LEFT, padx=5, pady=5)

root.mainloop()

On my Windows 10 laptop, as soon as the "Plot" button is pushed, the tkinter root window dramatically shrinks.在我的 Windows 10 笔记本电脑上,只要按下“绘图”按钮,tkinter 根 window 就会急剧缩小。 Interestingly, I do not see this same behavior on my Linux Mint laptop.有趣的是,我在 Linux Mint 笔记本电脑上没有看到同样的行为。

The desired behavior is for a plot to be shown on the screen (later, when plt.show() is to be called), not embedded in the tkinter window, and not affecting the tkinter window at all. The desired behavior is for a plot to be shown on the screen (later, when plt.show() is to be called), not embedded in the tkinter window, and not affecting the tkinter window at all.

I had the exact same problem.我有同样的问题。 I don't really have a clear answer, but I experienced this issue only when using python 3.7 not when using python 3.6.我真的没有明确的答案,但我仅在使用 python 3.7 时遇到此问题,而不是在使用 python 3.6 时遇到此问题。 So my only suggestion is to change your python version as long as you don't specifically need python 3.7所以我唯一的建议是改变你的 python 版本,只要你不特别需要 python 3.7

Also you can take a look at this post: Tkinter window changes dimensions or resolution when I use pyplot你也可以看看这篇文章: Tkinter window changes dimensions or resolution when I use pyplot

It's a similar issue and it can be fixed by adjusting the window layout settings on windows.这是一个类似的问题,可以通过调整 windows 上的 window 布局设置来解决。 It might not be exactly what you're looking for but give it a try.它可能不是您正在寻找的东西,但请尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM