Autocomplete using List of Colours as source

Autocomplete using Colour list as source

Tkinter autocomplete to browse and select colour names and update the background color of widget

List of colour names

Here is the list of colour names with RGB values. By using Pandas we will create DataFrame by reading the excel file. From the Name column of the DataFrame we will create the list and use the same as Data source for our Autocomplete.
import pandas as pd 
df=pd.read_excel("D:\\my_data\\tk-colours.xlsx") # Path of the file. 
Read the tutorial on Autocomplete.
Here we are only replacing the Source of data by using above defined my_list.
import pandas as pd 
df=pd.read_excel("D:\\my_data\\tk-colours.xlsx") # Path of the file. 
my_list=df['Name'].values.tolist() # list as data source  
# data source is ready ## Start the Tkinter code 

import tkinter as tk
import re # import regular expression library 
from tkinter import END
my_w = tk.Tk()
my_w.geometry("410x400")  # Size of the window 
my_w.title("")  # Adding a title
font1=('Times',24,'bold') # font size and style 
l0=tk.Label(text='Autocomplete',font=font1) # adding label at top

def my_upd(my_widget): # On selection of option 
    my_w1 = my_widget.widget
    index = int(my_w1.curselection()[0]) # position of selection
    value = my_w1.get(index) # selected value 
    e1_str.set(value) # set value for string variable of Entry 
    l1.delete(0,END)     # Delete all elements of Listbox
def my_down(my_widget): # down arrow is clicked 
    l1.focus()  # move focus to Listbox
    l1.selection_set(0) # select the first option 
e1_str=tk.StringVar()  # string variable   
e1=tk.Entry(my_w,textvariable=e1_str,font=font1) # entry    
# listbox 
l1 = tk.Listbox(my_w,height=6,font=font1,relief='flat',
    bg='SystemButtonFace',highlightcolor= 'SystemButtonFace')

def get_data(*args): # populate the Listbox with matching options 
    search_str=e1.get() # user entered string 
    l1.delete(0,END)     # Delete all elements of Listbox
    for element in my_list:
            l1.insert(tk.END,element)#add matching options to Listbox
#l1.bind('<<ListboxSelect>>', my_upd)
e1.bind('<Down>', my_down) # down arrow key is pressed
l1.bind('<Right>', my_upd) # right arrow key is pressed
l1.bind('<Return>', my_upd)# return key is pressed 
e1_str.trace('w',get_data) #    
#print(my_w['bg']) # reading background colour of window 
my_w.mainloop()  # Keep the window open

Tkinter Autocomplete using Entry & Listbox. MySQL table or Google sheets as data source for Autocomplete.
Python Tkinter Projects
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer