Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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 Tkinter在窗格窗口中动态调整小部件的大小_Python_Tkinter - Fatal编程技术网

Python Tkinter在窗格窗口中动态调整小部件的大小

Python Tkinter在窗格窗口中动态调整小部件的大小,python,tkinter,Python,Tkinter,我目前有一个带有两个标签窗格的窗口。在右窗格中,我有三个LabelFrame。当我调整窗口大小时,最底部的LabelFrame会变大,但顶部的两个仍然是我在设置其高度时指定的大小。我想要的是,当窗口在Y轴上调整大小时,它们三个都会均匀地增长。这可能吗 import tkinter as tk if __name__ == '__main__': appHeight=720 aspectRatio=16/9 appWidth=int(appHeight*aspectRati

我目前有一个带有两个标签窗格的窗口。在右窗格中,我有三个LabelFrame。当我调整窗口大小时,最底部的LabelFrame会变大,但顶部的两个仍然是我在设置其高度时指定的大小。我想要的是,当窗口在Y轴上调整大小时,它们三个都会均匀地增长。这可能吗

import tkinter as tk
if __name__ == '__main__':
    appHeight=720
    aspectRatio=16/9
    appWidth=int(appHeight*aspectRatio)
    app=tk.Tk()
    app.title("Title")
    app.minsize(width=appWidth,height=appHeight)
    #================================================================================
    # Setup Panes
    #================================================================================
    #Create Left Pane for settings
    leftPane = tk.PanedWindow(bd=4,relief='raised',bg='red')
    leftPane.pack(fill=tk.BOTH,expand=1)
    #Add Settings Frame to Pane
    settingsFrame = tk.LabelFrame(leftPane,text='Signature Filters',padx=5,pady=5,width=int(appWidth/4))
    leftPane.add(settingsFrame)

    #Create Right Pane for charts
    rightPane = tk.PanedWindow(leftPane,orient=tk.VERTICAL,bd=4,relief=tk.SUNKEN,bg='blue')
    leftPane.add(rightPane)
    #Add Depth Frame to Pane
    depthFrame = tk.LabelFrame(rightPane,text='Depth Signature',padx=5,pady=5,height=int(appHeight/3))
    rightPane.add(depthFrame)
    #Add Velocity Frame to Pane
    velocityFrame = tk.LabelFrame(rightPane,text='Velocity Signature',padx=5,pady=5,height=int(appHeight/3))
    rightPane.add(velocityFrame)
    #Add Depth Frame to Pane
    currentFrame = tk.LabelFrame(rightPane,text='Current Signature',padx=5,pady=5,height=int(appHeight/3))
    rightPane.add(currentFrame)

app.mainloop()

您需要设置窗扇位置。我编写了一些代码,当右侧窗格的大小发生变化时,使右侧的所有窗格都相等

import tkinter as tk

if __name__ == '__main__':
    appHeight=720
    aspectRatio=16/9
    appWidth=int(appHeight*aspectRatio)
    app=tk.Tk()
    app.title("Title")
    app.minsize(width=appWidth,height=appHeight)
    #================================================================================
    # Setup Panes
    #================================================================================
    #Create Left Pane for settings
    leftPane = tk.PanedWindow(bd=4,relief='raised',bg='red')
    leftPane.pack(fill=tk.BOTH,expand=1)
    #Add Settings Frame to Pane
    settingsFrame = tk.LabelFrame(leftPane, text='Signature Filters',padx=5,pady=5,width=int(appWidth/4))
    leftPane.add(settingsFrame)

    #Create Right Pane for charts
    rightPane = tk.PanedWindow(leftPane, orient=tk.VERTICAL, bd=4, relief=tk.SUNKEN, bg='blue')

    leftPane.add(rightPane)
    #Add Depth Frame to Pane
    depthFrame = tk.LabelFrame(rightPane, text='Depth Signature', padx=5, pady=5, height=int(appHeight/3))
    rightPane.add(depthFrame)
    #Add Velocity Frame to Pane
    velocityFrame = tk.LabelFrame(rightPane, text='Velocity Signature', padx=5, pady=5, height=int(appHeight/3))
    rightPane.add(velocityFrame)
    #Add Depth Frame to Pane
    currentFrame = tk.LabelFrame(rightPane, text='Current Signature', padx=5, pady=5, height=int(appHeight/3))
    rightPane.add(currentFrame)

    def set_sash(_):
        size = rightPane.winfo_height()//3
        for idx in range(len(rightPane.panes())-1):
            rightPane.sash_place(idx, 4, (idx+1)*size)
    rightPane.bind('<Configure>', set_sash)

app.mainloop()
将tkinter作为tk导入
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
appHeight=720
aspectRatio=16/9
appWidth=int(appHeight*aspectRatio)
app=tk.tk()
附录标题(“标题”)
app.minsize(宽度=appWidth,高度=appHeight)
#================================================================================
#设置窗格
#================================================================================
#为设置创建左窗格
leftPane=tk.PanedWindow(bd=4,relief='risted',bg='red')
leftPane.pack(fill=tk.BOTH,expand=1)
#将设置框架添加到窗格
settingsFrame=tk.LabelFrame(左窗格,text='Signature Filters',padx=5,pady=5,width=int(appWidth/4))
leftPane.add(设置框架)
#为图表创建右窗格
右窗格=tk.PanedWindow(左窗格,方向=tk.VERTICAL,bd=4,浮雕=tk.sinken,bg='blue')
添加(右窗格)
#将深度框架添加到窗格
depthFrame=tk.LabelFrame(右窗格,text='Depth Signature',padx=5,pady=5,height=int(appHeight/3))
右窗格。添加(深度框架)
#将速度帧添加到窗格
velocityFrame=tk.LabelFrame(右窗格,text='Velocity Signature',padx=5,pady=5,height=int(appHeight/3))
右窗格。添加(velocityFrame)
#将深度框架添加到窗格
currentFrame=tk.LabelFrame(右窗格,text='Current Signature',padx=5,pady=5,height=int(appHeight/3))
右窗格。添加(当前帧)
def set_窗框(u):
size=rightPane.winfo_height()//3
对于范围内的idx(len(rightPane.panes())-1):
右窗格。窗扇位置(idx,4,(idx+1)*尺寸)
右窗格。绑定(“”,设置窗框)
app.mainloop()

添加每个窗格时,需要将
拉伸
选项定义为字符串“始终”

rightPane.add(depthFrame, stretch="always")
rightPane.add(velocityFrame, stretch="always")
rightPane.add(currentFrame, stretch="always")
stretch
接受以下值:

  • 始终此窗格将始终拉伸
  • 第一个只有当此窗格是第一个窗格(最左侧或最顶部)时,它才会拉伸
  • last只有当此窗格是最后一个窗格(最右侧或最底部)时,它才会拉伸。这是默认值
  • 中间只有当此窗格不是第一个或最后一个窗格时,它才会拉伸
  • 永不此窗格永远不会拉伸
这些信息来自规范的tcl/tk文档部分。

上面的“stretch='always'”正是我所需要的。我非常感谢您在编写函数方面的努力!