Tkinter 奇怪的滚动条
Tkinter weird scrollbar
我正在尝试编写一个小脚本,其中包含两个列表框及其各自的滚动条。但是滚动条表现得很奇怪。考虑以下代码:
from Tkinter import *
class App:
def __init__(self, master):
self.mylist = Listbox(master, height = 30)
self.mylist.grid(row = 0, column = 0)
for i in range(200):
self.mylist.insert(END, str(i))
self.scroll = Scrollbar(master)
self.scroll.grid(row = 0, column = 1, sticky = N + S)
self.mylist.command = self.scroll.set
self.scroll.config(command = self.mylist.yview)
root = Tk()
app = App(root)
root.mainloop()
在我的电脑上,滚动条直到结束才出现,当它位于中间下方的某个位置时,列表框到达内容的末尾。当您到达某个点时,滚动条会回到开头。
为什么我会出现这种奇怪的行为?
您没有正确连接列表框和滚动条。而不是
self.mylist.command = self.scroll.set
使用
self.mylist.config(yscrollcommand = self.scroll.set)
我正在尝试编写一个小脚本,其中包含两个列表框及其各自的滚动条。但是滚动条表现得很奇怪。考虑以下代码:
from Tkinter import *
class App:
def __init__(self, master):
self.mylist = Listbox(master, height = 30)
self.mylist.grid(row = 0, column = 0)
for i in range(200):
self.mylist.insert(END, str(i))
self.scroll = Scrollbar(master)
self.scroll.grid(row = 0, column = 1, sticky = N + S)
self.mylist.command = self.scroll.set
self.scroll.config(command = self.mylist.yview)
root = Tk()
app = App(root)
root.mainloop()
在我的电脑上,滚动条直到结束才出现,当它位于中间下方的某个位置时,列表框到达内容的末尾。当您到达某个点时,滚动条会回到开头。
为什么我会出现这种奇怪的行为?
您没有正确连接列表框和滚动条。而不是
self.mylist.command = self.scroll.set
使用
self.mylist.config(yscrollcommand = self.scroll.set)