![](/img/trans.png)
[英]Tkinter: How to get frame in canvas window to expand to the size of the canvas?
[英]How to expand tkinter treeview column past window frame?
我有一個 tkinter Treeview 小部件,它有幾列和一個垂直和水平滾動條。 當樹中的項目數大於 treeview 小部件的大小時,垂直滾動條起作用,但是水平滾動條似乎沒有機會工作。 當我 select 一個列使其變大(即拖動“加載規范”以使“梁規范”離開屏幕)時,水平滾動條將激活,但只要列邊緣的 go 將所有列重新調整為適合框架而不是保持放大並允許我使用滾動條。 請參閱下圖,了解我正在談論的內容以及生成 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.