使Treeview在自定义行数下可滚动

时间:2018-12-27 23:06:35

标签: python python-3.x tkinter treeview

在此树形视图中,我想存储行高为500的行(例如)。如您所见,我附加了一个滚动条,该滚动条允许Treeview滚动,但是Treeview不可滚动。我认为这是由于树视图在滚动之前需要一定数量的行,即使无法看到下一行也是如此。

# Components for PatrolOverview
POStyle=ttk.Style()
POStyle.configure('POStyle.Treeview', rowheight=500)
PatrolView = ttk.Treeview(PatrolOverview,style='POStyle.Treeview')
PatrolTitleLabel = tk.Label(PatrolOverview, text="Patrol Overview", font=TitleFont, bg="white")
PatrolTitleLabel.grid(row=1, column=1, columnspan=5)
PatrolView["columns"] = ("image", "patrolname", "patrolleader", "patrolaleader", "score")
PatrolView.grid(row=2, column=1)
PatrolView.heading("patrolname", text="Patrol Name", anchor="w")
PatrolView.column("patrolname", anchor="center", width=70)
PatrolView.heading("patrolleader", text="Patrol Leader", anchor="w")
PatrolView.column("patrolleader", anchor="center", width=70)
PatrolView.heading("patrolaleader", text="Assistant Patrol Leader", anchor="w")
PatrolView.column("patrolaleader", anchor="center", width=70)
PatrolView.heading("score", text="Patrol Score", anchor="w")
PatrolView.column("score", anchor="center", width=70)
PatrolView.grid(row=2, column=1, columnspan=5)
PatrolViewScrollbar = ttk.Scrollbar(PatrolOverview, orient="vertical", command=PatrolView.yview)
PatrolView.configure(yscroll=PatrolViewScrollbar.set)
PatrolViewScrollbar.grid(row=2, column=6, sticky="ns")

由于我使用的是.grid方法,因此无法给出树状视图的准确像素测量值,因此这里是一个屏幕截图。 treeview

如图所示,树视图仅显示一行(应为三行),并且滚动条不起作用。

0 个答案:

没有答案