Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_auto_complete_search.py
- from tkinter import *
- root = Tk()
- root.title('Auto Complete Search')
- root.geometry("500x300")
- # Update the listbox
- def update(data):
- # Clear the listbox
- my_list.delete(0, END)
- # Add to listbox
- for item in data:
- my_list.insert(END, item)
- # Update entry box with listbox clicked
- def fillout(e):
- # Delete whatever is in the entry box
- my_entry.delete(0, END)
- # Add clicked list item to entry box
- my_entry.insert(0, my_list.get(ANCHOR))
- # Create function to check entry vs listbox
- def check(e):
- # grab what was typed
- typed = my_entry.get()
- if typed == '':
- data = names
- else:
- data = []
- data_substr = []
- for item in names:
- if typed.lower() in item.lower():
- if typed.lower()[0] == item.lower()[0]:
- data.append(item)
- else:
- data_substr.append(item)
- data += data_substr
- # update our listbox with selected items
- update(data)
- # Create a label
- my_label = Label(root, text="Start Typing...",
- font=("Helvetica", 14), fg="grey")
- my_label.pack(pady=20)
- # Create an entry box
- my_entry = Entry(root, font=("Helvetica", 20))
- my_entry.pack()
- # Create a listbox
- my_list = Listbox(root, width=50)
- my_list.pack(pady=40)
- # Create a list of names
- names = '''
- Aaliyah
- Abby
- Abigail
- Adaline
- Adara
- Addison
- Adelaide
- Adele
- Adeline
- Adira
- Adria
- Adrianna
- Alana
- Alba
- Alejandra
- Alessandra
- Alessia
- Aletta
- Alexa
- Alexandria
- Alexia
- Alexina
- Alexis
- Alice
- Alicia
- Alina
- Alisha
- Alison
- Alissa
- Allegra
- Allie
- Allison
- Alouetta
- Althea
- Alyssa
- Amalie
- Amara
- Amber
- Amelia
- Amira
- Anabelle
- Anais
- Anastasia
- Anaya
- Andrea
- Angel
- Angelica
- Angelina
- Angelique
- Anika
- Anisa
- Anna
- Annabel
- Annabella
- Annabelle
- Annamaria
- Anne
- Annie
- Annika
- Antoinette
- Antonietta
- Anya
- April
- Ari
- Aria
- Arianna
- Ariel
- Ariella
- Arielle
- Asha
- Ashlyn
- Asia
- Athena
- Aubrey
- Audrey
- Aurelia
- Aurelie
- Aurielle
- Aurora
- Autumn
- Ava
- Avelyn
- Avery
- Aviva
- Azalea
- Bailee
- Bailey
- Barbara
- Beatrice
- Beatrix
- Beatriz
- Bella
- Belle
- Beth
- Bethany
- Betsy
- Bianca
- Blair
- Blossom
- Bonita
- Bonnie
- Breanna
- Brenda
- Brianna
- Bridget
- Bridgette
- Briella
- Brielle
- Brittany
- Brooke
- Brooklyn
- Bryce
- Cadence
- Caitlin
- Caitlyn
- Cami
- Camila
- Camilla
- Camille
- Camryn
- Candace
- Capri
- Caprice
- Cara
- Carina
- Carissa
- Carla
- Carly
- Carmella
- Carmen
- Carolina
- Caroline
- Carrie
- Cassandra
- Cassia
- Cassidy
- Cassie
- Catalina
- Caterina
- Catherine
- Cecile
- Cecilia
- Celeste
- Celine
- Charlotte
- Chelsea
- Cheyenne
- Chloe
- Christie
- Christina
- Christine
- Ciara
- Cindy
- Claire
- Clara
- Clarissa
- Clarita
- Clementine
- Colleen
- Courtney
- Crystal
- Cynthia
- Dahlia
- Daisy
- Dana
- Danica
- Daniella
- Danielle
- Danika
- Daphne
- Darcy
- Darlene
- Davina
- Deanna
- Deborah
- Delaney
- Delilah
- Delphine
- Denise
- Desiree
- Destiny
- Diana
- Diane
- Dinah
- Diva
- Dixie
- Dominique
- Donna
- Dora
- Dorothy
- Eden
- Edith
- Edna
- Eileen
- Elaine
- Eleanor
- Elena
- Elisa
- Elisabeth
- Elisa
- Elizabeth
- Ella
- Elle
- Ellen
- Ellie
- Eloise
- Elora
- Elsa
- Elsie
- Emelia
- Emelie
- Emilia
- Emilie
- Emily
- Emma
- Emmeline
- Erika
- Erin
- Esmeralda
- Estella
- Estelle
- Eva
- Evangeline
- Eve
- Evelyn
- Everlee
- Everly
- Evie
- Evita
- Faith
- Fay
- Faye
- Felicia
- Flavia
- Flora
- Florence
- Francesca
- Francine
- Frida
- Gabriella
- Gabrielle
- Geneva
- Genevieve
- Gianna
- Giavanna
- Gigi
- Ginevra
- Ginger
- Gloria
- Goldie
- Grace
- Gracie
- Graciela
- Gwendoline
- Gwendolyn
- Hailey
- Haley
- Harmony
- Hayley
- Hazel
- Heidi
- Helena
- Henna
- Holly
- Irene
- Irina
- Iris
- Isabel
- Isabella
- Isabelle
- Isadora
- Ivana
- Ivory
- Ivy
- Jacqueline
- Jada
- Jade
- Janet
- January
- Jasmine
- Jaylene
- Jaylin
- Jaz
- Jazmin
- Jeanette
- Jemma
- Jenna
- Jenny
- Jensen
- Jessa
- Jessica
- Jewel
- Jillian
- Jocelyn
- Jolene
- Jolie
- Josephina
- Josephine
- Josie
- Joy
- Joyce
- Jude
- Judith
- Jules
- Julia
- Julianna
- Julianne
- Julie
- Juliet
- Julietta
- Juliette
- June
- Justine
- Kaitlyn
- Kalani
- Kara
- Karen
- Karina
- Karla
- Karra
- Katarina
- Katelyn
- Katherine
- Kathleen
- Katie
- Katrina
- Kaya
- Kayla
- Kaylee
- Keiko
- Keilani
- Keira
- Keisha
- Kelly
- Kelsey
- Kendra
- Khloe
- Kiana
- Kiara
- Kiera
- Kimberly
- Kinsley
- Kirstie
- Kirsten
- Kitty
- Krissy
- Kristen
- Kristina
- Kyla
- Kylie
- Kyra
- Lacey
- Lacie
- Laila
- Lainie
- Lana
- Lani
- Lara
- Larissa
- Laurel
- Lauren
- Laurie
- Layla
- Laynee
- Leandra
- Leila
- Leilani
- Lenora
- Leona
- Leslie
- Lexi
- Leyla
- Lia
- Liana
- Libby
- Liberty
- Lila
- Lilah
- Lilia
- Lilian
- Lilianna
- Lillian
- Lily
- Linda
- Lisa
- Livia
- Lola
- Loreene
- Loretta
- Lori
- Lorraine
- Lotus
- Louisa
- Louise
- Lucille
- Lucy
- Lydia
- Lyra
- Mabel
- Mackenzie
- Madalyn
- Madeleine
- Madeline
- Madelyn
- Madison
- Mae
- Maggie
- Mai
- Mallory
- Marcy
- Margaret
- Maria
- Marianna
- Marianne
- Marie
- Marietta
- Marilyn
- Marina
- Marisa
- Marissa
- Marla
- Marlee
- Martha
- Martina
- Mary
- Matilda
- Mavis
- May
- Maya
- Megan
- Melina
- Melody
- Mercedes
- Merida
- Mia
- Michelle
- Mila
- Miranda
- Mireya
- Miriam
- Molly
- Monette
- Monroe
- Mya
- Mylah
- Nadia
- Nancy
- Naomi
- Natalia
- Natalie
- Naya
- Nellie
- Nessa
- Nevada
- Nikita
- Nina
- Noemi
- Nora
- Nova
- Nya
- Oceania
- Octavia
- Olivia
- Ottavia
- Paige
- Pamela
- Paris
- Patience
- Patricia
- Paula
- Pearl
- Penelope
- Phoebe
- Phoenix
- Princess
- Priscilla
- Quinn
- Rachel
- Raina
- Raine
- Raven
- Rayna
- Raynee
- Rebecca
- Reece
- Reese
- Remi
- Remy
- Renee
- Rey
- Rhea
- Ria
- Riley
- Riva
- Rochelle
- Romina
- Romy
- Rosa
- Rosalie
- Rosalina
- Rosalind
- Rose
- Rosemary
- Rosetta
- Rosie
- Roxy
- Ruby
- Rylee
- Sabrina
- Sadie
- Samantha
- Sara
- Sarah
- Sasha
- Savannah
- Scarlet
- Scarlett
- Selena
- Serena
- Shannon
- Sharon
- Shayna
- Shea
- Shelby
- Shirley
- Sienna
- Sierra
- Silvia
- Simona
- Simone
- Sinead
- Skye
- Skylar
- Skyler
- Sofia
- Solei
- Sophia
- Sophie
- Stassi
- Stella
- Summer
- Susan
- Susanna
- Susannah
- Suzannah
- Suzanne
- Sydney
- Sylvia
- Tabitha
- Talia
- Tammy
- Tara
- Tatiana
- Teagan
- Terra
- Theodora
- Tia
- Tiana
- Tiffany
- Tori
- Tracy
- Trinity
- Trista
- Tulia
- Valentina
- Valentine
- Valeria
- Vanessa
- Venus
- Vera
- Veronica
- Victoria
- Vienna
- Viola
- Violet
- Violette
- Virginia
- Vita
- Vivian
- Viviana
- Vivienne
- Winona
- Xena
- Yasmin
- Yolanda
- Yvonne
- Zahara
- Zahra
- Zara
- Zelda
- Zoe
- Zoey
- Zoie
- Zola
- Zuri
- '''.splitlines()[1:-1]
- # Add the names to our list
- update(names)
- # Create a binding on the listbox onclick
- my_list.bind("<<ListboxSelect>>", fillout)
- # Create a binding on the entry box
- my_entry.bind("<KeyRelease>", check)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement