Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在不移动任何按钮的情况下更新tkinter_Python 3.x_Matplotlib_Tkinter - Fatal编程技术网

Python 3.x 在不移动任何按钮的情况下更新tkinter

Python 3.x 在不移动任何按钮的情况下更新tkinter,python-3.x,matplotlib,tkinter,Python 3.x,Matplotlib,Tkinter,更新前: 更新后: 我的更新代码: def plot(data,the_main): fig = Figure(figsize=(5,5),dpi=100) plot1 = fig.add_subplot() plot1.plot(data) canvas = FigureCanvasTkAgg(fig,master = the_main) canvas.draw() # placing the canvas on the T

更新前:

更新后:


我的更新代码:
def plot(data,the_main):
    fig = Figure(figsize=(5,5),dpi=100)
    plot1 = fig.add_subplot()
    plot1.plot(data)

    canvas = FigureCanvasTkAgg(fig,master = the_main)   
    canvas.draw() 
  
    # placing the canvas on the Tkinter window 
    canvas.get_tk_widget().grid(row=5,column=6)
  
    # creating the Matplotlib toolbar 
    # toolbar = NavigationToolbar2Tk(canvas,the_main) 
    # toolbar.update() 
访问更新之前的我的代码(与窗口相关):

我正在尝试将
matplotlib
嵌入
tkinter

它正在工作,但并不像我预期的那样。
我刚刚尝试创建一个新窗口,专门用于图形。然而,
我的桌面屏幕乱七八糟。

所以我的问题是:
如何操作我的代码,使
matplotlib
嵌入
tkinter
中 将
按钮保持在它们的位置上


我无法运行您的代码,但我猜这样可以:

canvas.get_tk_widget().grid(row=5,column=6, columnspan=7)
这样做之所以有效,是因为将绘图放在单个列中。每列都有一个统一的宽度,因此它强制第6列与绘图一样宽。通过使绘图跨越多个列,可以避免调整单个列的大小以适应整个绘图


可以说,一个更好的解决方案是把你的按钮放在一个框架中,把框架放在顶部,然后把绘图放在下面<代码>网格在创建小部件矩阵时非常有用,但在您的情况下,您没有这样做。

哦,是的,它确实有效…看起来像是
html
sorta,但您怎么知道呢?。我在文档中搜索了
tkinter.grid()
,但没有找到任何对我有用的东西
canvas.get_tk_widget().grid(row=5,column=6, columnspan=7)