- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I change the text of the Tkinter Listbox item?
To display a list of items in the application, Tkinter provides a Listbox widget. It is used to create a list of items vertically. When we want to change the text a specific Listbox item, then we have to first select the item by iterating over the listbox.curselection() and insert a new item after deletion. To insert a item in the list, you can use 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()
Executing the above code will display a window that contains a list of items.
Now, select an item from the list and click "Edit". It will edit the selected item in the list.
- Related Articles
- How to edit a Listbox item in Tkinter?
- How to fully change the color of a Tkinter Listbox?
- Default to and select the first item in Tkinter Listbox
- How to directly modify a specific item in a TKinter listbox?
- How can I change the text color with jQuery?
- How to set the font size of a Tkinter Canvas text item?
- Python Tkinter – How do I change the text size in a label widget?
- How to change the text color of Menu item in Android?
- How can I change the text color of the Navigation Bar on iOS?
- Is it possible to color a specific item in a Tkinter Listbox widget?
- How to change the Text color of Menu item in Android using Kotlin?
- How to clear a Tkinter ListBox?
- How do I center the text in a Tkinter Text widget?
- How do I find out the size of a canvas item in Tkinter?
- How to change the size of text on a label in Tkinter?