[英]Tkinter can't increase frame/grid row height
我找不到增加包含 Treeview 的框架高度的方法。 我正在使用網格,因為稍后我將添加更多小部件。 我試過做這些,但它們似乎都不起作用:
import tkinter as tk
import tkinter.ttk as ttk
class ViewWindow(tk.Frame):
def __init__(self, root):
self.root = root
self.root.resizable(False,False)
self.root.geometry('1000x700+500+150')
self.root.title('View Appointments')
self.widgets()
def widgets(self):
self.canvas = tk.Canvas(self.root, width=1000, height=81, background='blue')
self.canvas.grid(row=0, column=0, columnspan=20)
self.header = tk.Label(self.root, text="ABC", background='blue', font=("",50), fg='white')
self.header.grid(row=0, column=0, columnspan=20, sticky="W")
self.topLeftLabel = tk.Label(self.root, text="DEF",font=("",50))
self.topLeftLabel.grid(row=1, column=0, sticky="W", columnspan=20)
self.frame = tk.Frame(self.root, height=1000, borderwidth=1)
self.frame.grid(row=2, column=1, sticky="NEWS", columnspan=18, rowspan=20)
###creating table
self.table = ttk.Treeview(self.frame)
self.table["columns"]=("a","b","c","d","e")
self.table.column("#0")
self.table.column("a", width=100)
self.table.column("b", width=100)
self.table.column("c", width=200)
self.table.column("d", width=150)
self.table.column("e", width=100)
self.table.heading("#0")
self.table.heading("a", text="a",anchor=tk.W)
self.table.heading("b", text="b",anchor=tk.W)
self.table.heading("c", text="c",anchor=tk.W)
self.table.heading("d", text="d",anchor=tk.W)
self.table.heading("e", text="e",anchor=tk.W)
self.table['show'] = 'headings'
###random data
for i in range(20):
self.table.insert("",i, value=(i,i,i,i,i))
self.table.pack(fill='both')
self.root.grid_rowconfigure(2, weight=1)
self.root.grid_rowconfigure(2, minsize=1000)
def main():
root = tk.Tk()
app = ViewWindow(root)
root.mainloop()
if __name__ == '__main__':
main()
任何幫助,將不勝感激。 謝謝你。
當您打包包含 TreeView 的框架時:
self.table.pack(expand=tk.YES, fill=tk.BOTH)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.