【问题标题】:Tkinter Scrollbar jumps to top of listbox after selection选择后 Tkinter 滚动条跳到列表框顶部
【发布时间】:2017-12-04 17:33:42
【问题描述】:

I have a scrollbar for a listbox, and when a selection is made past the original view of the listbox (you scroll down to select something), after the selection, the scrollbar jumps to the top of the listbox.我希望列表框保持在它当前的位置,就像任何其他一般滚动条的工作方式一样。这是列表框的定义

def createListBox(self):
    self.frame = Frame(self)#Frame that holds the scrollbar and listbox
    self.scrollbar = Scrollbar(self.frame)
    self.waiver_menu = Listbox(self.frame, width = 20, height = 9, yscrollcommand = self.scrollbar.set)
    self.scrollbar.config(command = self.waiver_menu.yview)
    self.frame.grid(row = self.row_count, column = self.col_count, rowspan = 3)
    self.waiver_menu.grid(row = self.row_count, column = self.col_count, rowspan = 3)
    self.scrollbar.grid(row = self.row_count, column = self.col_count+1, rowspan = 3, sticky = N+S+W)

    self.waiver_menu.bind("<Double-Button-1>", self.chosen)

【问题讨论】:

  • 为我工作。视窗 10,蟒蛇 3.5。双击第 20 项,将其选中,Listbox 视图仍在第 20 项上。
  • 请提供更多代码。此功能不足以解决您的问题,因为它也适用于我。问题可能出在代码中的其他地方。请提供Minimal, Complete, and Verifiable example
  • 抱歉代码不足。谢谢你的帮助。我不认为它在其他地方,但我忘记了我在另一个位置刷新列表框导致滚动条跳到顶部。

标签: python tkinter listbox scrollbar


【解决方案1】:

我发现我正在通过删除和插入新项目来刷新另一个位置的列表框,这就是它让您回到顶部的原因。带有滚动条实现的列表框的这种定义有效!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 2015-06-16
    • 2023-04-07
    • 1970-01-01
    • 2022-10-02
    相关资源
    最近更新 更多