2017-09-26 106 views
1

我希望我的樹視圖完全適合我的窗口的幾何尺寸已爲我的GUI定義,但顯示不包括整個窗口顯示在中間。如何讓tkinter樹視圖適合您的框架

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() 

我試圖把它放在一個框架,但它並不顯示樹視圖的內容。此代碼

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

tree = ttk.Treeview(fr) 

回答

2

請以下行

tree.pack(fill='x') 

這將使用ROOT屏幕的整個空間替換下面的行

tree.pack() 

前: enter image description here 後: enter image description here

+0

@引爆大衆非常感謝這意味着默認情況下,包填充(Y軸) –

+0

是,歡迎您。請upvote我的答案和標記是完整的。謝謝。 –

+0

那麼爲什麼不能將y軸和x軸都放在包裏呢。問這是因爲當我改變主題,如果默認填充x軸 –