[英]Multiple frames in a single tab 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' . 我有以下代码部分(不完整),我想在ttk“笔记本”的单个选项卡中包含几个框架。
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. 我希望“表格”位于窗口的中央,但可以根据窗口的大小进行调整。
Thank you for your help! 谢谢您的帮助!
grid_propagate
isn't a solution to any of your problems. grid_propagate
您的任何问题。
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. 这是Frame
类存在的主要原因之一-构建便于布局的小部件容器。
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; 尽管这也可能与您使用grid
将框架放置在笔记本中有关。 you can't use grid
to place items in a notebook. 您不能使用grid
将项目放置在笔记本中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.