繁体   English   中英

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

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

我有一个 tkinter Treeview 小部件,它有几列和一个垂直和水平滚动条。 当树中的项目数大于 treeview 小部件的大小时,垂直滚动条起作用,但是水平滚动条似乎没有机会工作。 当我 select 一个列使其变大(即拖动“加载规范”以使“梁规范”离开屏幕)时,水平滚动条将激活,但只要列边缘的 go 将所有列重新调整为适合框架而不是保持放大并允许我使用滚动条。 请参阅下图,了解我正在谈论的内容以及生成 treeview 的代码片段。 感谢您在提供此问题的解决方案方面提供的任何帮助。

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

可能有点晚了,但我想你会在这个 SO 帖子中找到解决方案: Python tkinter treeview column sizes 如果在实例化列时设置了stretch=False ,您应该能够将其扩展到可见框架的边缘之外而不会回弹。 所以对于你的代码:

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

祝你好运!

暂无
暂无

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

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