Tkinter Treeview网格对齐问题

时间:2015-03-25 01:50:07

标签: python-2.7 tkinter treeview

在扩展应用程序窗口时,如何使树视图小部件坚持Noth (到工具栏)。

它坚持西南和东部,但不是北部。

使用:

self.tree.grid(row=1,column=0,sticky=N+W+E+S)

我 这是tree.grid对齐配置

...
    self.vsb = ttk.Scrollbar(master, orient=VERTICAL, command=self.tree.yview)
    self.hsb = ttk.Scrollbar(master, orient=HORIZONTAL, command=self.tree.xview)
    self.vsb.grid(row=1, column=1, sticky='ns')
    self.hsb.grid(row=2, column=0, sticky='ew')
    self.tree.configure(yscrollcommand=self.vsb.set)
    self.tree.configure(xscrollcommand=self.hsb.set)

    self.tree.grid(row=1,column=0,sticky=N+W+E+S)
...

这是工具栏网格配置(如果它导致问题)

...
        self.toolbar = Frame(master, bg="blue")
        self.upButton = Button(self.toolbar, text="Up", command=self.doNothing, padx=10, pady=10)
        self.upButton.grid(row=0,column=0,sticky=N+W)

        self.downButton = Button(self.toolbar, text="Down", command=self.doNothing, padx=10, pady=10)
        self.downButton.grid(row=0,column=1, sticky=N+W)

        self.insupButton = Button(self.toolbar, text="Insert UP", command=lambda: self.insertUp(self.tree), padx=10, pady=10)
        self.insupButton.grid(row=0,column=2, sticky=N+W)

        self.insdownButton = Button(self.toolbar, text="Insert Down", command=lambda: self.insertDown(self.tree), padx=10, pady=10)
        self.insdownButton.grid(row=0,column=3, sticky=N+W)

        self.delbrButton = Button(self.toolbar, text="Delete branch", command=lambda: self.deleteBr(self.tree), padx=10, pady=10)
        self.delbrButton.grid(row=0,column=4, sticky=N+W)

        self.deltreeButton = Button(self.toolbar, text="Delete entire tree", command=lambda: self.deleteTr(self.tree), padx=10, pady=10)
        self.deltreeButton.grid(row=0,column=5, sticky=N+W)

        self.searchButton = Button(self.toolbar, text='Search', command=lambda: self.searchTr(self.tree), padx=10, pady=10)
        self.searchButton.grid(row=0,column=6, sticky=N+W)

        self.calcButton = Button(self.toolbar, text='Calc', command=lambda: self.calcTree(self.tree), padx=10, pady=10)
        self.calcButton.grid(row=0,column=7, sticky=N+W)

        self.toolbar.grid(row=0,column=0, sticky=N+W)
...

发布时的应用

enter image description here

观察到的结果:应用程序按比例放大

enter image description here

观察到的结果:应用程序缩小(与工具栏重叠)

enter image description here

期望的结果:应用扩大规模

enter image description here

1 个答案:

答案 0 :(得分:6)

你的树 坚持北方,只是行的顶部比你意识到的更低。您需要为一行或多行赋予权重,以便tkinter将为该行分配额外的空间(并且)为默认权重为零的任何行。

例如:

master.grid_rowconfigure(1, weight=1)

有关网格算法如何工作的明确参考,请参阅http://tcl.tk/man/tcl8.5/TkCmd/grid.htm#M32