单个标签中的多个框架 ttk.Notebook [英] Multiple frames in a single tab ttk.Notebook

查看:31
本文介绍了单个标签中的多个框架 ttk.Notebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码段(不完整),我想在 ttk 'Notebook' 中将多个框架包含到单个选项卡中.

I have the following sections of code (not complete) where I would like to contain several frames into a single tab in the ttk 'Notebook' .

win1 = Tk()    
n = ttk.Notebook(win1)

choice_frame = ttk.Frame(n, style="Black.TLabel")
choice_frame.grid(row=2, column=1, sticky="N,S,E,W", padx=1, pady=1)
choice_frame.grid_columnconfigure(0, weight=3)
choice_frame.grid_rowconfigure(0, weight=1)

frame_text = ttk.Frame(n, style="Black.TLabel")
frame_text.grid(row=0, column=0, sticky = "N")
frame_text.grid_columnconfigure(0, weight=3)
frame_text.grid_rowconfigure(0, weight=1)

frame_table = ttk.Frame(n, style="Black.TLabel")
frame_table.grid(row=2, column=0, padx=1, pady=1, sticky= " N, S, E, W ")
frame_table.grid_columnconfigure(0, weight=3)
frame_table.grid_rowconfigure(0, weight=1)

n.add(frame_table, text="One") # Would like same tab not two separate ones
n.add(choice_frame, text="One")
n.grid(sticky="N")

我还想知道是否有一种方法可以让每个维度在窗口被拖出和最大化时自动调整.我以前试过:

I would also like to know if there's a way of allowing every dimension to adjust automatically when the window is dragged out and maximised. I have previously tried:

frame_table.grid_propagate(0)

但这似乎不允许高度和宽度尺寸保持一致.我希望我的桌子"位于窗口的中央,但要根据窗口大小进行调整.

But this doesn't seem to allow the height as well as width dimension to stick. I would like my 'table' to be in the center of the window but adjust with the window size.

感谢您的帮助!

推荐答案

grid_propagate 不能解决您的任何问题.

grid_propagate isn't a solution to any of your problems.

每个选项卡只能包含一个框架,但该框架可以包含您想要的任何内容.因此,为选项卡创建一个容器框架,然后将所有其他框架放入容器框架中.这是 Frame 类存在的主要原因之一——构建便于布局的小部件容器.

Each tab can contain only a single frame, but that single frame can contain whatever you want. So, create one container frame for the tab and then put all your other frames in the container frame. This is one of the main reasons the Frame class exists -- to build widget containers that facilitate layout.

至于调整大小,问题可能是您没有为主窗口的行和列添加权重.虽然这也可能与您使用 grid 将框架放置在笔记本中的事实有关;您不能使用 grid 在笔记本中放置项目.

As for the resizing, the problem is probably that you're not adding a weight to the rows and columns of the main window. Though it could also be related to the fact you are using grid to place the frames in the notebook; you can't use grid to place items in a notebook.

这篇关于单个标签中的多个框架 ttk.Notebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆