我尝试采用Tkinter,treeview 不使用 window 调整大小,几乎没有修改。
import tkinter as tk
from tkinter import ttk
import random
class App():
def __init__(self):
self.root = tk.Tk()
self.frame = tk.Frame(self.root)
self.frame.pack(expand=True, fill=tk.BOTH)
self.tree = ttk.Treeview(self.frame, show="headings")
self.tree.pack(expand=True, )
self.frameBT = tk.LabelFrame(self.root,text='Buttons')
self.frameBT.pack(expand=True, fill=tk.X)
self.button = ttk.Button(self.frameBT, text="Fill", command=self.fill)
self.button.pack(side=tk.BOTTOM,expand=True)
self.fill()
self.root.mainloop()
def fill(self):
if self.has_data():
self.tree.delete(*self.tree.get_children())
i = random.randrange(1,10)
self.tree["columns"]=tuple([str(i) for i in range(i)])
for col in self.tree['columns']:
self.tree.heading(col, text="Column {}".format(col), anchor=tk.CENTER)
self.tree.column(col, anchor=tk.CENTER)
j = random.randrange(10)
for j in range(j):
self.tree.insert("", "end", values = tuple([k for k in range(i)]))
def has_data(self):
has_tree = self.tree.get_children()
return True if has_tree else False
App()
目前,当我垂直拉伸窗口时,我得到了
我的问题是,当我调整主窗口的大小时,如何将“按钮”保持在最底部,而树视图框架的底部会上下移动。