最近,我使用tkinter
TreeView
显示许多列Python
。具体来说,树视图中有 49 列数据。我用grid
管理我的小部件。
我发现树视图的宽度仅取决于列的宽度。
我的问题是,如何设置 Treeview 的宽度。 (默认宽度是所有列宽度的总和)
When all my column width is set as 20. This is 49 columns. :)
这是我的主要代码:
frame = Frame(self.master, width = 1845, height = 670)
frame.place(x = 20, y = 310)
tree_view = Treeview(frame, height = 33, selectmode = "extended")
for i in range(len(id_list)):
tree_view.column(id_list[i], width = width_list[i], anchor = CENTER)
tree_view.heading(id_list[i] , text = text_list[i])
tree_view["show"] = "headings"
# Omit the declaration of scrollbar
tree_view['yscroll'] = self.y_scollbar.set
tree_view['xscroll'] = self.x_scollbar.set
tree_view.grid(row = 0, column = 0, sticky = NSEW)
for item in detail_info_list:
tree_view.insert("",0, text = str(item.id), value=(...))
id_list
,width_list
,text_list
用于存储列信息。detail_info_list
是存储Treeview中显示的数据。
我的目标是当我定义某个列的大宽度(例如:3000)时,我的树视图可以按我的预期显示数据。但是树视图在我的屏幕上,水平滚动条也无法滑动。
When 17th column is set as 1500:
我看不到按钮,也无法滑动水平滚动条。
另外,我尝试了一些解决方案。
- 定义一个框架作为 Treeview 的父级。并定义宽度和高度来约束Treeview。但这没有用。
- 我查阅了一些文档并搜索了这个问题。我没有找到任何将宽度设置为常数的解决方案。