AJN
AJN

Reputation: 1206

Tkinter Treeview grid alignment issue

How can I make the treeview widget stick to the Noth (to the toolbar) when scaling up the application window.

It sticks to the west South and Est, but not the North.

using :

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

I This is the tree.grid alignment configuration

...
    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)
...

This is the toolbar grid config (in case it causes the issue)

...
        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)
...

Application at launch:

enter image description here

Observed result: Application scaled up

enter image description here

Observed result: Application scaled down (overlaps with the toolbar)

enter image description here

Desired result: Application scaled up

enter image description here

Upvotes: 0

Views: 1468

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386362

Your tree is sticking to the north, it's just that the top of the row is further down than you realize. You need to give one or more rows a weight, so that tkinter will allocate extra space to that row (and not to any rows with the default weight of zero).

For example:

master.grid_rowconfigure(1, weight=1)

For a definitive reference to how the grid algorithm works see http://tcl.tk/man/tcl8.5/TkCmd/grid.htm#M32

Upvotes: 6

Related Questions