【问题标题】:Tkinter, treeview doesn't resizeTkinter,树视图不调整大小
【发布时间】:2017-12-22 01:01:40
【问题描述】:

当我调整窗口的高度时如何调整树视图的大小? 我尝试设置sticky="sn",我尝试用fill='y' 打包树视图,但没有任何效果。

import tkinter as tk
from tkinter.ttk import Treeview

root = tk.Tk()

f1 = tk.Frame(root)
f2 = tk.Frame(root)

f1.grid(column=0, row=0, sticky="s")
f2.grid(column=1, row=0, sticky="n")
root.rowconfigure(0, weight=1)

Treeview(f1).pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()

root.mainloop()

【问题讨论】:

    标签: python-3.x tkinter treeview


    【解决方案1】:

    您需要sticky="ns" 在窗口中调整Frame 的大小,并在Frame 中使用fill='y', expand=True 调整Treeview 的大小

    import tkinter as tk
    from tkinter.ttk import Treeview
    
    root = tk.Tk()
    
    f1 = tk.Frame(root)
    f2 = tk.Frame(root)
    
    f1.grid(column=0, row=0, sticky="ns")
    f2.grid(column=1, row=0, sticky="n")
    root.rowconfigure(0, weight=1)
    
    Treeview(f1).pack(expand=True, fill='y')
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    
    root.mainloop()
    

    【讨论】:

    • 该死的,我离得太近了哈哈。非常感谢!
    猜你喜欢
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    相关资源
    最近更新 更多