简体   繁体   中英

How to let tkinter treeview fit your frame

I want my treeview to fully fit the geometry size of my window have defined for my GUI but the display doesn't cover the entire window been display in the middle.

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

I tried to put it in a Frame but that doesn't also display the content for the treeview. This the code

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

tree = ttk.Treeview(fr) 

Please replace the following line

tree.pack()

with following line

tree.pack(fill='x')

This will use the COMPLETE SPACE of ROOT screen.

Before: 在此处输入图片说明 After: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM