简体   繁体   English

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

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

Goal:目标:

  • Paned frame / window with a Treeview that has a scrollbar带有滚动条的 Treeview 的窗格框架 / window
  • Resizing the frame should resize the Treeview and maintain the scrollbar visible调整框架大小应调整 Treeview 的大小并保持滚动条可见

I have tried the following code:我尝试了以下代码:

    # 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滚动条是这样显示的

I also tried fitting the Treeview & Scrollbar in a separate frame (using grid), which results in the scrollbar being displayed as expected (right of the Treeview).我还尝试将 Treeview 和滚动条安装在单独的框架中(使用网格),这会导致滚动条按预期显示(树视图的右侧)。 The problem with this approach is that the Treeview is not resized anymore when dragging the sash of the paned window.这种方法的问题是,当拖动窗格 window 的窗扇时,不再调整 Treeview 的大小。

The scrollbar shouldn't be a child of the treeview.滚动条不应是 treeview 的子级。 The treeview and scrollbar should share the same parent. treeview 和滚动条应该共享同一个父级。

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

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