Reputation: 1
I have a tkinter Treeview widget with several columns and a vertical and horizontal scrollbar. The vertical scrollbar works when the number of items in the tree are larger than the size of the treeview widget however the the horizonal scrollbar does not have a chance to work it seems. When I select a column to make it larger (i.e. drag 'Load Spec.' such that 'Beam Spec.' is off the screen) the horizontal scrollbar activates but as soon as a let go of the column edge all the columns resize back to fit the frame rather than staying enlarged and allowing me to use the scrollbar. See image below of what I am talking about and the snippet of code that generates the treeview. Thank you for any help in providing a solution to this issue.
Treeview Image with Scrollbars
headings = ['Set #', 'Set Name', 'Joint Spec.', 'Load Spec.', 'Beam Spec.']
tree_contain = Treeview(display_result_set_frame, columns=headings, show='headings', height=4)
tree_scrollx = Scrollbar(display_result_set_frame)
tree_scrolly = Scrollbar(display_result_set_frame)
tree_scrollx.configure(command=tree_contain.xview, orient=HORIZONTAL)
tree_scrolly.configure(command=tree_contain.yview)
tree_contain.configure(xscrollcommand=tree_scrollx.set, yscrollcommand=tree_scrolly.set)
tree_scrolly.pack(side=RIGHT, fill=Y)
tree_scrollx.pack(side=BOTTOM, fill=X)
tree_contain.pack(side=LEFT, fill=X, expand=True)
tree_index = 0
for col in headings:
tree_contain.heading(col, text=col.title())
tree_width = [40, 200, 100, 100, 100]
tree_anchor = [CENTER, W, CENTER, W, W]
tree_contain.column(col, width=tree_width[tree_index], minwidth=tree_width[tree_index], anchor=tree_anchor[tree_index])
tree_index += 1
Upvotes: 0
Views: 1136
Reputation: 409
Probably a bit late, but I think you'll find the solution in this SO post: Python tkinter treeview column sizes. If you set stretch=False
when instantiating a column, you should be able to expand it beyond the edge of the visible frame without it snapping back. So for your code:
for col in headings:
tree_contain.heading(col, text=col.title())
tree_width = [40, 200, 100, 100, 100]
tree_anchor = [CENTER, W, CENTER, W, W]
tree_contain.column(col, stretch=False, width=tree_width[tree_index], minwidth=tree_width[tree_index], anchor=tree_anchor[tree_index],)
tree_index += 1
Good luck!
Upvotes: 1