使用scroll=Scrollbar(self.无滚动条)
不知道为什么添加不上,将scroll=Scrollbar(self.frame)修改为scroll=Scrollbar(self.root)时表格又不显示
class Manager(Frame):
def __init__(self, parent,excel):
super().__init__(parent)
self.excel=excel
self.root=parent
self.title_ws=title
# self.pack(expand=1, fill="both")
self.frame = Frame(self)
self.frame.pack(expand=1, fill="both", padx=5, pady=5)
def __check_all(self):
scroll=Scrollbar(self.frame)
scroll.pack(side='right',fill='y')
columns=('#0', '#1', '#2', '#3', '#4', '#5', '#6', '#7')
self.tree = Treeview( columns=columns,yscrollcommand=scroll.set)
scroll.config(command=self.tree.yview)
self.tree.grid(row=1, rowspan=5,column=1,columnspan=8)
看起来你的Scrollbar是正确添加的,但是没有正确显示,这可能是由于你的Frame大小没有被正确设置导致的。你可以尝试将self.frame的高度设置为一个固定的值,例如
self.frame = Frame(self, height=300)
如果你的表格可以正常显示,那么你可以通过调整self.frame的大小来调整表格和滚动条的位置。如果你想让self.frame填满整个父容器,可以使用pack()方法,例如:
self.frame.pack(expand=True, fill='both')