Tkinter 'sticky' 和 'rowconfigure' 都没有填空 space

Tkinter both 'sticky' and 'rowconfigure' did not fill the empty space

我在根目录中有 2 个框架,分别称为 "header_frame" 和 "activity_frame",它们都在同一列中,即 "column=0"。我希望两个框架都可以调整大小,以匹配其根父级填充所有空 space,如下所示:

我已经尝试了所有可能的网格配置,包括在 'root' 上设置 'rowconfigure',将 activity_frame 设置为坚持 "North",即 header_frame,最后但是尤其是我还尝试将 header_frame 固定在南方,这是我不想要的结果,因为那些框架共享相同的大小(我希望 header_frame 具有 'maxsize' 属性但遗憾的是它没有'没有)。所以这是我试过的代码:

self.root = root
self.column = ""
self.search = ""
self.root.minsize(500,480)
self.comboboxValue = None
self.root.title("CUCI (CSV Unique Column Identifier)")
self.root.configure(background="powder blue")
self.root.grid_columnconfigure(0,weight=1)
self.root.grid_rowconfigure(0,weight=1)
self.root.grid_rowconfigure(1,weight=1)

#header frame
self.header_frame = tk.Frame(self.root)
self.header_frame.grid(row=0, column=0,sticky="NEW")
self.header_frame.grid_columnconfigure(0,weight=1)
self.header_frame.grid_rowconfigure(0,weight=1)
self.header_frame.configure(background="grey")

#activity Frame
self.activity_frame = tk.Frame(self.root)
self.activity_frame.grid(row=1, column=0,sticky="NEWS")
self.activity_frame.grid_columnconfigure(0,weight=1)
self.activity_frame.grid_rowconfigure(0,weight=1)
self.activity_frame.configure(background="grey",pady=1)

这是我的代码的布局结果,我不希望这样:

关键是我想用 activity_frame 填充那些空的 spaces 并粘贴在 'header_frame' 上。拜托我不想使用 pack(self.activity_frame.pack(填充=tk.X))。我只是想用grid因为好用

出现间隙的原因是因为您没有将 header 框架粘在给定的 space 底部。如果将 header 的 sticky 属性更改为 "nsew",您将看到 header 填充额外的 space.

self.header_frame.grid(row=0, column=0,sticky="nesw")

我猜你不希望 header 框架这么高。如果是这种情况,请将第 0 行的权重设为 0 而不是 1。这样,所有额外未分配的 space 都将分配给第 1 行。

self.root.grid_rowconfigure(0,weight=0)

执行此操作并添加几个其他小部件来模拟您的屏幕后,这就是它的样子: