Home > Mobile >  Why no scroll bars on Table?
Why no scroll bars on Table?

Time:11-07

I am trying to get scroll bars on the table, but they are just not showing up no matter how I try. Here is what I have so far:

'''

# Table Frame
tree_frame = Frame(root, bg="#ecf0f1")
tree_frame.place(x=0, y=380, width=1980, height=520)
style = ttk.Style()
style.configure("mystyle.Treeview", font=('Calibri', 18),
                rowheight=50)  # Modify the font of the body
style.configure("mystyle.Treeview.Heading", font=('Calibri', 18))  # Modify the font of the headings
tv = ttk.Treeview(tree_frame, columns=(1, 2, 3, 4, 5, 6), style="mystyle.Treeview")


#scrollbar
tree_scroll = Scrollbar(tree_frame)
tree_scroll.pack(side=RIGHT, fill=Y)

tree_scroll = Scrollbar(tree_frame,orient='horizontal')
tree_scroll.pack(side= BOTTOM,fill=X)

my_tree = ttk.Treeview(tree_frame,yscrollcommand=tree_scroll.set, xscrollcommand =tree_scroll.set)


tv.column("# 1",anchor=W, stretch=NO, width=100)
tv.heading("# 1", text="ID")
tv.column("# 2", anchor=W, stretch=NO)
tv.heading("# 2", text="Catagory")
tv.column("# 3", anchor=W, stretch=NO, width=150)
tv.heading("# 3", text="Brand")
tv.column("# 4", anchor=W, stretch=NO, width=255)
tv.heading("# 4", text="Model")
tv.column("# 5", anchor=W, stretch=NO, width=375)
tv.heading("# 5", text="Serial#")
tv.column("# 6", anchor=W, stretch=NO)
tv.heading("# 6", text="Notes")

tv['show'] = 'headings'
tv.bind("<ButtonRelease-1>", getData)
tv.pack(fill=X)

''' Anyone have any ideas? Here is my output:

enter image description here

CodePudding user response:

The scrollbars are there. The problem is that you're using place on tree_frame which prevents the window from resizing to fit the widgets. If you manually make the window large enough, the scrollbar will become visible.

If you use pack or grid with appropriate options, the window will automatically resize to make all of the widgets visible.

tree_frame.pack(side="top", fill="both", expand=True)
  • Related