Horizontal Scrollbar for Treeview

Viewed 751

I have attached a vertical and horizontal scrollbar for a tkinter treeview in Python. For some reason, the horizontal bar is not working. The treeview is filled with a directory structure with root selected by the user, and the scrollbar does not become active when I expand the paths. The example bellow does not present that structure, but has a long string inside the treeview, and even here the scrollbar does not work.

import tkinter as tk 
from tkinter import ttk

root = tk.Tk()
root.title("Files for Replication")

tree_frame = tk.Frame(root) 
tree_frame.place(relx=0, rely=0, relwidth=0.5, relheight=1)

# Treeview
treeview = ttk.Treeview(tree_frame)
treeview.heading("#0", text="Name", anchor=tk.W)
treeview.place(relx=0.02, rely=0.3, relwidth=0.9, relheight=0.5)
treeview.bind('<Shift-Right>', callback_main)
treeview.bind('<Double-1>', callback_dependencies)
treeview.insert('', '0', 'item1', text=150*"a")
tree_scrolly = ttk.Scrollbar(tree_frame, orient=tk.VERTICAL, command=treeview.yview)
tree_scrolly.place(relx=0.91, rely=0.3, relwidth=0.03, relheight=0.49)
treeview.config(yscrollcommand=tree_scrolly.set)
tree_scrollx = ttk.Scrollbar(tree_frame, orient=tk.HORIZONTAL, command=treeview.xview)
tree_scrollx.place(relx=0.02, rely=0.79, relwidth=0.9, relheight=0.03)
treeview.config(xscrollcommand=tree_scrollx.set)

Treeview Capture image: Treeview Capture

I would really appreciate some help with this problem, since I have another tkinter appication that uses almost the same code (to be fair, the scrollbars are attached to a Listbox, but that should not be an issue) and is up and running. Thanks in advance.

0 Answers
Related