Multiple frames in a single tab ttk.Notebook

邮差的信 提交于 2019-12-08 06:17:30

问题


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.

Thank you for your help!


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/11227388/multiple-frames-in-a-single-tab-ttk-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!