I am unable to make the treeview widget on Tkinter fill the whole column. I tried it using column configure with weight but it does not work. When I run it, the treeview displays it as given in the link to the pic. How can i get the treeview to display the directories which fill the window right down to the bottom.
class dir_tree(object):
def __init__(self, master, path):
self.nodes = dict()
frame = tk.Frame(master)
self.tree = ttk.Treeview(frame)
ysb = ttk.Scrollbar(frame, orient='vertical', command=self.tree.yview)
xsb = ttk.Scrollbar(frame,orient='horizontal',command=self.tree.xview)
self.tree.configure( xscroll=master.winfo_screenheight())
self.tree.heading('#0', text='Manga Directory', anchor='w')
self.tree.grid(column = 0, sticky = 'ns')
ysb.grid(row=0, column=1, sticky='ns')
xsb.grid(row=1, column=0, sticky='ew')
frame.grid(column = 0, sticky = 'ns')
self.tree.columnconfigure(0, weight=1)
abspath = os.path.abspath('/home/user/Desktop/')
self.insert_node('', abspath, abspath)
self.tree.bind('<<TreeviewOpen>>', self.open_node)
def insert_node(self, parent, text, abspath):
node = self.tree.insert(parent, 'end', text=text, open=False)
if os.path.isdir(abspath):
self.nodes[node] = abspath
self.tree.insert(node, 'end')
def open_node(self, event):
node = self.tree.focus()
abspath = self.nodes.pop(node, None)
if abspath:
self.tree.delete(self.tree.get_children(node))
for p in os.listdir(abspath):
self.insert_node(node, p, os.path.join(abspath, p))
if __name__ == "__main__":
dirr = dir_tree(root, path='/home/user/Desktop/')
How can i make the vertical scrollbar fill over the whole window height in left rather than only a part of window as shown?
So I managed to make the scrollbar fit the entire window. Here's my solution:
class dir_tree(object):
def __init__(self, master, path):
self.nodes = dict()
notebook = ttk.Notebook(master, width = 2000)
self.tree = ttk.Treeview(notebook)
ysb = ttk.Scrollbar(notebook, orient='vertical', command=self.tree.yview)
xsb = ttk.Scrollbar(notebook, orient='horizontal',command=self.tree.xview)
self.tree.configure(yscrollcommand=ysb.set, xscrollcommand=xsb.set)
self.tree.heading('#0', text='Manga Directory', anchor='w')
xsb.pack(side=tk.BOTTOM, fill=tk.X)
ysb.pack(side=tk.RIGHT, fill=tk.Y)
notebook.pack(side = LEFT,fill = tk.Y)
self.tree.pack(side = LEFT, fill = tk.BOTH, expand = True)
abspath = os.path.abspath('/home/user/Desktop/')
self.insert_node('', abspath, abspath)
self.tree.bind('<<TreeviewOpen>>', self.open_node)
def insert_node(self, parent, text, abspath):
node = self.tree.insert(parent, 'end', text=text, open=False)
if os.path.isdir(abspath):
self.nodes[node] = abspath
self.tree.insert(node, 'end')
def open_node(self, event):
node = self.tree.focus()
abspath = self.nodes.pop(node, None)
if abspath:
self.tree.delete(self.tree.get_children(node))
for p in os.listdir(abspath):
self.insert_node(node, p, os.path.join(abspath, p))
if __name__ == "__main__":
dirr = dir_tree(root, path='/home/user/Desktop/') # Path to Downloads