วิดเจ็ต Treeview ออกแบบมาเพื่อแสดงข้อมูลในโครงสร้างแบบลำดับชั้น สามารถใช้เพื่อแสดงไดเร็กทอรี ไดเร็กทอรีย่อย หรือไฟล์ในรูปแบบของรายการ รายการที่อยู่ในกล่องรายการจะเรียกว่ารายการกล่องรายการ
วิดเจ็ต treeview ประกอบด้วยคุณสมบัติและแอตทริบิวต์มากมาย ซึ่งเราสามารถเปลี่ยนแปลงหรือแก้ไขคุณสมบัติเริ่มต้นได้ เราสามารถเปลี่ยนพื้นหลังของวิดเจ็ต treeview โดยกำหนด 'background' คุณสมบัติในตัวสร้าง
ตัวอย่าง
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the window
win.geometry("700x350")
# Create a Listbox widget
lb = Listbox(win, width=100, height=10, background="purple4", foreground="white", font=('Times 13'),selectbackground="black")
lb.pack()
# Select the list item and delete the item first
# Once the list item is deleted, we can insert a new item in the listbox
def edit():
for item in lb.curselection():
lb.delete(item)
lb.insert("end", "foo")
# Add items in the Listbox
lb.insert("end", "item1", "item2", "item3", "item4", "item5")
# Add a Button To Edit and Delete the Listbox Item
ttk.Button(win, text="Edit", command=edit).pack()
win.mainloop() ผลลัพธ์
หากเราเรียกใช้โค้ดข้างต้น จะแสดงหน้าต่างที่มีวิดเจ็ต treeview ที่มีสีพื้นหลังที่แตกต่างกันและบางรายการในนั้น
