ในการแสดงรายการของรายการในแอปพลิเคชัน Tkinter จัดเตรียมวิดเจ็ตกล่องรายการ ใช้สร้างรายการสิ่งของในแนวตั้ง เมื่อเราต้องการเปลี่ยนข้อความของรายการกล่องรายการเฉพาะ อันดับแรกเราต้องเลือกรายการนั้นโดยวนซ้ำที่ listbox.curselection() และแทรกรายการใหม่หลังจากลบ หากต้องการแทรกรายการในรายการ คุณสามารถใช้ listbox.insert(**items)
ตัวอย่าง
# 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)
lb.pack(expand=True, fill=BOTH)
# Define a function to edit the listbox ite
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() ผลลัพธ์
การรันโค้ดด้านบนจะแสดงหน้าต่างที่มีรายการไอเทม

ตอนนี้ เลือกรายการจากรายการแล้วคลิก "แก้ไข" มันจะแก้ไขรายการที่เลือกในรายการ
