Tkinter网格布局不会扩展

时间:2015-08-07 19:26:38

标签: python user-interface python-3.x tkinter python-3.4

我试图设计侧边栏,这应该像Google的侧边栏菜单一样(例如在收件箱或播放音乐,浏览器版本中)。 我使用网格布局但它不会扩展。我已经查了一下,尽管添加了Foosticky = "nesw",但右边的框架不会展开并填充根。

rowconfigure(0, weigth = 1)

这是我得到的。我左边的按钮应该是在白色背景框架上。框架和分隔符应该向下到应用程序窗口的底部。

Result display

提前致谢。

1 个答案:

答案 0 :(得分:5)

如果你想要按钮'容器从窗口顶部一直延伸到底部,尝试在根目录上调用frame.rowconfigure(0, weight = 1)。如果您希望按钮均匀分布,而不是调用frame.rowconfigure,请为{em>框架的每个行调用len(buttons),从0到from tkinter import * from tkinter import ttk buttons = ["Button", "Button", "Button", "Button", "Button", "Button", "Button", "Button", "Button", "Button"] # List of contacts root = Tk() root.title('MyApp v0.1') root.geometry('800x600') #root['bg'] = "white" root.rowconfigure(0, weight=1) # Side menu frame = Frame(root, background = "white") for i in range(len(buttons)): Button(frame, background = "white", text = buttons[i], command = None).grid(row = i, column = 0) frame.rowconfigure(i, weight = 1) frame.grid(row = 0, column = 0, sticky = "nesw") sep = ttk.Separator(root, orient = "vertical") sep.rowconfigure(0, weight = 1) sep.columnconfigure(1, weight = 1) sep.grid(row = 0, column = 1, padx = 5, sticky = "nesw")

form#form-reflow(action='/', method='post', 
                    onsubmit="docreflow()")
    input#textinp(type="text", name="textinp")
    input#submit(type="submit", name="submit") 

结果:

enter image description here