
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Color Specific Item in a Tkinter Listbox Widget
Tkinter ListBox widget is generally used for creating a list of items in the form of a list. The items can be chosen through the mouse buttons whenever we click a particular List Item. Each item in the ListBox is configured with the default color, which can be changed by defining the ‘background’ and ‘foreground’ color in itemconfig(options) method.
Example
In this example, we will create a ListBox that contains a list of items. We will provide different colors to a few of the list items.
#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Create a ListBox listbox= Listbox(win) listbox.pack(expand=True, fill=BOTH) #Adding Items in the ListBox for item in ["C++","Python", "JavaScript", "Go"]: listbox.insert("end", item) #Configure the listitems listbox.itemconfig(1,{'bg':'OrangeRed3'}) listbox.itemconfig(3,{'bg':'khaki3'}) win.mainloop()
Running the above code will display listbox with list items. List Items color can be configured by changing the value of ‘bg’.
Output
Advertisements