繁体   English   中英

在窗格 window 中使用滚动条调整 Treeview 的大小不起作用

[英]Resizing Treeview with scrollbar in paned window does not work

目标:

  • 带有滚动条的 Treeview 的窗格框架 / window
  • 调整框架大小应调整 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)

滚动条是这样显示的

我还尝试将 Treeview 和滚动条安装在单独的框架中(使用网格),这会导致滚动条按预期显示(树视图的右侧)。 这种方法的问题是,当拖动窗格 window 的窗扇时,不再调整 Treeview 的大小。

滚动条不应是 treeview 的子级。 treeview 和滚动条应该共享同一个父级。

暂无
暂无

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

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