- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 to change the background color of a Treeview in Tkinter?
The Treeview widget is designed to display the data in a hierarchical structure. It can be used to display the directories, child directories or files in the form of a list. The items present in the Listbox are called Listbox items.
The treeview widget includes many properties and attributes through which we can change or modify its default properties. We can change the background of a treeview widget by defining the 'background' property in the constructor.
# 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()
If we run the above code, it will display a window with a treeview widget having a distinct background color and some items in it.
- How to change the background color of a tkinter Canvas dynamically?
- Dynamically change the widget background color in Tkinter
- How to make a Button Hover to change the Background Color in Tkinter?
- How to change the menu background color of Tkinter's OptionMenu widget?
- How to set the background color of a ttk.Combobox in tkinter?
- How to reset the background color of a Python Tkinter button?
- How to change the color of a Tkinter label programmatically?
- How to fully change the color of a Tkinter Listbox?
- How to change the background color using jQuery?
- How to change the background color of the font in PowerShell?
- Change the background color of a button with CSS
- How do I change the background of a Frame in Tkinter?
- How to change the Background Color of Text in C# Console
- How to change the color of ttk button in Tkinter?
- How to change header background color of a table in Java