我正在尝试将带有日期的Treeview小部件放在带有滚动条的框架中,并且我希望Treeview垂直填充...但是无论我尝试什么(使用pack(fill ='y')或grid(sitcky ='ns'),它不会在“ y”方向上延伸。
这是我要使用的代码:
class TVTEf2(ttk.Frame):
def __init__(self,parent):
ttk.Frame.__init__(self,parent)
# self.grid(sticky='ns')
self.pack(anchor='w',fill='both')
self.initialize()
def initialize(self):
self.tree = ttk.Treeview(self,selectmode='browse')
self.vsb = ttk.Scrollbar(self,orient="vertical",command=self.tree.yview)
self.tree.configure(yscrollcommand=self.vsb.set)
self.columns = ("Ligne","Voie","Support","Date SPOT","Statut")
self.csize = [50,50,50,75,50]
self.tree["columns"] = self.columns
self.tree['show'] = 'headings'
self.tree.insert("",'end',text="L1",values=(format(570000,'06.0f'),"V1",'323/01','01/01/2018',"Non fait"))
self.tree.insert("",'end',text="L2",values=(format(570000,'06.0f'),"V1",'323/03','01/01/2018',"Non fait"))
self.tree.insert("",'end',text="L3",values=(format(570000,'06.0f'),"V1",'323/05','01/01/2018',"Non fait"))
self.tree.insert("",'end',text="L4",values=(format(570000,'06.0f'),"V2",'323/08','01/01/2018',"Non fait"))
self.vsb.pack(anchor='e', fill='y', side='left')
self.tree.pack(side='left',fill='both')
# self.vsb.grid(column=1,row=0,sticky='ns')
# self.tree.grid(column=0,row=0,sticky='ns')
for k in range(len(self.columns)):
col =self.columns[k]
sz = self.csize[k]
self.tree.column(col,minwidth=0,width=sz, stretch='no')
for col in self.columns:
self.tree.heading(col, text=col, command=lambda _col=col: \
treeview_sort_column(self.tree, _col, False))
if __name__ == "__main__":
root = Tkinter.Tk()
root.rowconfigure(0, weight=0)
root.columnconfigure(0, weight=1)
root.title('')
pad=3
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
app = TVTEf2(root)
app.mainloop()
我得到的树视图很小...
如果有人有什么想法...非常感谢
答案 0 :(得分:0)
不完全是我想要的,但是我只是用Treeview小部件的“ height”参数“欺骗了”:
def initialize(self):
self.tree = ttk.Treeview(self,selectmode='browse',height = 36)
#^^^^^^^^^^^^
它仍然没有固定在底部,但是至少对于给定的屏幕分辨率,它具有正确的固定大小(几乎不是一个好的解决方案)