简体   繁体   English

如何将 tkinter treeview 列扩展到 window 框架?

[英]How to expand tkinter treeview column past window frame?

I have a tkinter Treeview widget with several columns and a vertical and horizontal scrollbar.我有一个 tkinter Treeview 小部件,它有几列和一个垂直和水平滚动条。 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.当树中的项目数大于 treeview 小部件的大小时,垂直滚动条起作用,但是水平滚动条似乎没有机会工作。 When I select a column to make it larger (ie 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.当我 select 一个列使其变大(即拖动“加载规范”以使“梁规范”离开屏幕)时,水平滚动条将激活,但只要列边缘的 go 将所有列重新调整为适合框架而不是保持放大并允许我使用滚动条。 See image below of what I am talking about and the snippet of code that generates the treeview.请参阅下图,了解我正在谈论的内容以及生成 treeview 的代码片段。 Thank you for any help in providing a solution to this issue.感谢您在提供此问题的解决方案方面提供的任何帮助。

Treeview Image with Scrollbars Treeview 带有滚动条的图像

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

Probably a bit late, but I think you'll find the solution in this SO post: Python tkinter treeview column sizes .可能有点晚了,但我想你会在这个 SO 帖子中找到解决方案: 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.如果在实例化列时设置了stretch=False ,您应该能够将其扩展到可见框架的边缘之外而不会回弹。 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!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM