如何解决在窗格窗口中使用滚动条调整 Treeview 的大小不起作用
目标:
- 带有滚动条的树状视图的窗格框架/窗口
- 调整框架大小应该调整树视图的大小并保持滚动条可见
我尝试了以下代码:
# set paned Windows layout,main stacked horizontally,left stacked vertically
self.pwMain = PanedWindow(orient=tk.HORIZONTAL)
self.pwMain.grid(sticky=tk.NSEW)
self.pwLeft = PanedWindow(orient=tk.VERTICAL)
self.pwLeft.grid(sticky=tk.NSEW)
# set editorText
self.editorText = ScrolledText(
self,wrap=tk.WORD,undo=True,relief=tk.FLAT)
self.editorText.grid(sticky=tk.NSEW)
self.pwLeft.add(self.editorText)
# set AutoCompleteList Tree
self.style = ttk.Style() # remove borders from TreeView
self.style.layout(
"Treeview",[('Treeview.treearea',{'sticky': 'nswe'})])
# only show headings columns,not root column of tree
self.autoCompleteList = Treeview(
self,columns=2,show=["headings"],selectmode='browse')
self.autoCompleteList["columns"] = ("#1","#2")
self.autoCompleteList.heading('#1',text='Record Name')
self.autoCompleteList.heading('#2',text='Record ID')
# Specify attributes of the columns (We want to stretch it!)
self.autoCompleteList.column('#1',stretch=tk.YES)
self.autoCompleteList.column('#2',stretch=tk.YES)
# autocomplete vertical scrollbar
self.aclvbar = AutoScrollbar(self.autoCompleteList,orient=tk.VERTICAL,command=self.autoCompleteList.yview)
self.autoCompleteList.configure(yscrollcommand=self.aclvbar.set)
self.autoCompleteList.grid(sticky=tk.NSEW)
self.aclvbar.grid(row=0,column=1,sticky='ns')
self.pwLeft.add(self.autoCompleteList)
The Scrollbar is displayed like this
我还尝试将 Treeview & Scrollbar 安装在单独的框架中(使用网格),这导致滚动条按预期显示(Treeview 的右侧)。这种方法的问题是在拖动窗格窗口的窗框时不再调整 Treeview 的大小。
解决方法
滚动条不应是树视图的子项。树视图和滚动条应该共享同一个父级。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。