如何让tkinter treeview适合您的框架

时间:2017-09-26 09:41:05

标签: python tkinter treeview frame

我希望我的树视图完全符合我为我的GUI定义的窗口的几何尺寸,但显示器不会覆盖整个窗口中间显示的内容。

from tkinter import ttk
import tkinter as tk


root = tk.Tk()
root.geometry("1200x680+50+20")


tree = ttk.Treeview(root)
tree.insert("", "0", "item1", text="LANGUAGE")
tree.insert("", "1", "item2", text="GUI")
tree.insert("item1", "0", text="pyhton")

#SUb treeview
style = ttk.Style(root)
style.configure("Treeview", rowheight=70)
tree.configure(style="Treeview")

    ############
tree.config(columns=("NOTE", "book"))   # this creates to seperate headings 
for treeview
tree.column("NOTE", width=300)
tree.heading("NOTE", text="Info")
tree.column("book", width=300)
tree.heading("book", text="profile")


tree.set("item1", "NOTE","Am using python version 3.6.1 \n on windows 
machine")
tree.set("item2","NOTE","This an example Tkinter Treeview in Python, which 
is from \nttk class make sure import ttk\n also from tkinter import *")


tree.pack()
root.mainloop()

我试图把它放在一个Frame中,但是它也不会显示树视图的内容。这个代码

fr = tk.Frame(root, width=1200, height=680, relief="groove") 

tree = ttk.Treeview(fr) 

1 个答案:

答案 0 :(得分:3)

请替换以下行

tree.pack()

以下行

tree.pack(fill='x')

这将使用ROOT屏幕的COMPLETE SPACE。

在: enter image description here 后: enter image description here