Advertisement
here2share

# Tk_auto_complete_search.py

Dec 29th, 2021
1,571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.17 KB | None | 0 0
  1. # Tk_auto_complete_search.py
  2.  
  3. from tkinter import *
  4.  
  5. root = Tk()
  6. root.title('Auto Complete Search')
  7. root.geometry("500x300")
  8.  
  9. # Update the listbox
  10. def update(data):
  11.     # Clear the listbox
  12.     my_list.delete(0, END)
  13.  
  14.     # Add to listbox
  15.     for item in data:
  16.         my_list.insert(END, item)
  17.  
  18. # Update entry box with listbox clicked
  19. def fillout(e):
  20.     # Delete whatever is in the entry box
  21.     my_entry.delete(0, END)
  22.  
  23.     # Add clicked list item to entry box
  24.     my_entry.insert(0, my_list.get(ANCHOR))
  25.  
  26. # Create function to check entry vs listbox
  27. def check(e):
  28.     # grab what was typed
  29.     typed = my_entry.get()
  30.  
  31.     if typed == '':
  32.         data = names
  33.     else:
  34.         data = []
  35.         data_substr = []
  36.         for item in names:
  37.             if typed.lower() in item.lower():
  38.                 if typed.lower()[0] == item.lower()[0]:
  39.                     data.append(item)
  40.                 else:
  41.                     data_substr.append(item)
  42.         data += data_substr
  43.  
  44.     # update our listbox with selected items
  45.     update(data)               
  46.  
  47.  
  48. # Create a label
  49. my_label = Label(root, text="Start Typing...",
  50.     font=("Helvetica", 14), fg="grey")
  51.  
  52. my_label.pack(pady=20)
  53.  
  54. # Create an entry box
  55. my_entry = Entry(root, font=("Helvetica", 20))
  56. my_entry.pack()
  57.  
  58. # Create a listbox
  59. my_list = Listbox(root, width=50)
  60. my_list.pack(pady=40)
  61.  
  62. # Create a list of names
  63. names = '''
  64. Aaliyah
  65. Abby
  66. Abigail
  67. Adaline
  68. Adara
  69. Addison
  70. Adelaide
  71. Adele
  72. Adeline
  73. Adira
  74. Adria
  75. Adrianna
  76. Alana
  77. Alba
  78. Alejandra
  79. Alessandra
  80. Alessia
  81. Aletta
  82. Alexa
  83. Alexandria
  84. Alexia
  85. Alexina
  86. Alexis
  87. Alice
  88. Alicia
  89. Alina
  90. Alisha
  91. Alison
  92. Alissa
  93. Allegra
  94. Allie
  95. Allison
  96. Alouetta
  97. Althea
  98. Alyssa
  99. Amalie
  100. Amara
  101. Amber
  102. Amelia
  103. Amira
  104. Anabelle
  105. Anais
  106. Anastasia
  107. Anaya
  108. Andrea
  109. Angel
  110. Angelica
  111. Angelina
  112. Angelique
  113. Anika
  114. Anisa
  115. Anna
  116. Annabel
  117. Annabella
  118. Annabelle
  119. Annamaria
  120. Anne
  121. Annie
  122. Annika
  123. Antoinette
  124. Antonietta
  125. Anya
  126. April
  127. Ari
  128. Aria
  129. Arianna
  130. Ariel
  131. Ariella
  132. Arielle
  133. Asha
  134. Ashlyn
  135. Asia
  136. Athena
  137. Aubrey
  138. Audrey
  139. Aurelia
  140. Aurelie
  141. Aurielle
  142. Aurora
  143. Autumn
  144. Ava
  145. Avelyn
  146. Avery
  147. Aviva
  148. Azalea
  149. Bailee
  150. Bailey
  151. Barbara
  152. Beatrice
  153. Beatrix
  154. Beatriz
  155. Bella
  156. Belle
  157. Beth
  158. Bethany
  159. Betsy
  160. Bianca
  161. Blair
  162. Blossom
  163. Bonita
  164. Bonnie
  165. Breanna
  166. Brenda
  167. Brianna
  168. Bridget
  169. Bridgette
  170. Briella
  171. Brielle
  172. Brittany
  173. Brooke
  174. Brooklyn
  175. Bryce
  176. Cadence
  177. Caitlin
  178. Caitlyn
  179. Cami
  180. Camila
  181. Camilla
  182. Camille
  183. Camryn
  184. Candace
  185. Capri
  186. Caprice
  187. Cara
  188. Carina
  189. Carissa
  190. Carla
  191. Carly
  192. Carmella
  193. Carmen
  194. Carolina
  195. Caroline
  196. Carrie
  197. Cassandra
  198. Cassia
  199. Cassidy
  200. Cassie
  201. Catalina
  202. Caterina
  203. Catherine
  204. Cecile
  205. Cecilia
  206. Celeste
  207. Celine
  208. Charlotte
  209. Chelsea
  210. Cheyenne
  211. Chloe
  212. Christie
  213. Christina
  214. Christine
  215. Ciara
  216. Cindy
  217. Claire
  218. Clara
  219. Clarissa
  220. Clarita
  221. Clementine
  222. Colleen
  223. Courtney
  224. Crystal
  225. Cynthia
  226. Dahlia
  227. Daisy
  228. Dana
  229. Danica
  230. Daniella
  231. Danielle
  232. Danika
  233. Daphne
  234. Darcy
  235. Darlene
  236. Davina
  237. Deanna
  238. Deborah
  239. Delaney
  240. Delilah
  241. Delphine
  242. Denise
  243. Desiree
  244. Destiny
  245. Diana
  246. Diane
  247. Dinah
  248. Diva
  249. Dixie
  250. Dominique
  251. Donna
  252. Dora
  253. Dorothy
  254. Eden
  255. Edith
  256. Edna
  257. Eileen
  258. Elaine
  259. Eleanor
  260. Elena
  261. Elisa
  262. Elisabeth
  263. Elisa
  264. Elizabeth
  265. Ella
  266. Elle
  267. Ellen
  268. Ellie
  269. Eloise
  270. Elora
  271. Elsa
  272. Elsie
  273. Emelia
  274. Emelie
  275. Emilia
  276. Emilie
  277. Emily
  278. Emma
  279. Emmeline
  280. Erika
  281. Erin
  282. Esmeralda
  283. Estella
  284. Estelle
  285. Eva
  286. Evangeline
  287. Eve
  288. Evelyn
  289. Everlee
  290. Everly
  291. Evie
  292. Evita
  293. Faith
  294. Fay
  295. Faye
  296. Felicia
  297. Flavia
  298. Flora
  299. Florence
  300. Francesca
  301. Francine
  302. Frida
  303. Gabriella
  304. Gabrielle
  305. Geneva
  306. Genevieve
  307. Gianna
  308. Giavanna
  309. Gigi
  310. Ginevra
  311. Ginger
  312. Gloria
  313. Goldie
  314. Grace
  315. Gracie
  316. Graciela
  317. Gwendoline
  318. Gwendolyn
  319. Hailey
  320. Haley
  321. Harmony
  322. Hayley
  323. Hazel
  324. Heidi
  325. Helena
  326. Henna
  327. Holly
  328. Irene
  329. Irina
  330. Iris
  331. Isabel
  332. Isabella
  333. Isabelle
  334. Isadora
  335. Ivana
  336. Ivory
  337. Ivy
  338. Jacqueline
  339. Jada
  340. Jade
  341. Janet
  342. January
  343. Jasmine
  344. Jaylene
  345. Jaylin
  346. Jaz
  347. Jazmin
  348. Jeanette
  349. Jemma
  350. Jenna
  351. Jenny
  352. Jensen
  353. Jessa
  354. Jessica
  355. Jewel
  356. Jillian
  357. Jocelyn
  358. Jolene
  359. Jolie
  360. Josephina
  361. Josephine
  362. Josie
  363. Joy
  364. Joyce
  365. Jude
  366. Judith
  367. Jules
  368. Julia
  369. Julianna
  370. Julianne
  371. Julie
  372. Juliet
  373. Julietta
  374. Juliette
  375. June
  376. Justine
  377. Kaitlyn
  378. Kalani
  379. Kara
  380. Karen
  381. Karina
  382. Karla
  383. Karra
  384. Katarina
  385. Katelyn
  386. Katherine
  387. Kathleen
  388. Katie
  389. Katrina
  390. Kaya
  391. Kayla
  392. Kaylee
  393. Keiko
  394. Keilani
  395. Keira
  396. Keisha
  397. Kelly
  398. Kelsey
  399. Kendra
  400. Khloe
  401. Kiana
  402. Kiara
  403. Kiera
  404. Kimberly
  405. Kinsley
  406. Kirstie
  407. Kirsten
  408. Kitty
  409. Krissy
  410. Kristen
  411. Kristina
  412. Kyla
  413. Kylie
  414. Kyra
  415. Lacey
  416. Lacie
  417. Laila
  418. Lainie
  419. Lana
  420. Lani
  421. Lara
  422. Larissa
  423. Laurel
  424. Lauren
  425. Laurie
  426. Layla
  427. Laynee
  428. Leandra
  429. Leila
  430. Leilani
  431. Lenora
  432. Leona
  433. Leslie
  434. Lexi
  435. Leyla
  436. Lia
  437. Liana
  438. Libby
  439. Liberty
  440. Lila
  441. Lilah
  442. Lilia
  443. Lilian
  444. Lilianna
  445. Lillian
  446. Lily
  447. Linda
  448. Lisa
  449. Livia
  450. Lola
  451. Loreene
  452. Loretta
  453. Lori
  454. Lorraine
  455. Lotus
  456. Louisa
  457. Louise
  458. Lucille
  459. Lucy
  460. Lydia
  461. Lyra
  462. Mabel
  463. Mackenzie
  464. Madalyn
  465. Madeleine
  466. Madeline
  467. Madelyn
  468. Madison
  469. Mae
  470. Maggie
  471. Mai
  472. Mallory
  473. Marcy
  474. Margaret
  475. Maria
  476. Marianna
  477. Marianne
  478. Marie
  479. Marietta
  480. Marilyn
  481. Marina
  482. Marisa
  483. Marissa
  484. Marla
  485. Marlee
  486. Martha
  487. Martina
  488. Mary
  489. Matilda
  490. Mavis
  491. May
  492. Maya
  493. Megan
  494. Melina
  495. Melody
  496. Mercedes
  497. Merida
  498. Mia
  499. Michelle
  500. Mila
  501. Miranda
  502. Mireya
  503. Miriam
  504. Molly
  505. Monette
  506. Monroe
  507. Mya
  508. Mylah
  509. Nadia
  510. Nancy
  511. Naomi
  512. Natalia
  513. Natalie
  514. Naya
  515. Nellie
  516. Nessa
  517. Nevada
  518. Nikita
  519. Nina
  520. Noemi
  521. Nora
  522. Nova
  523. Nya
  524. Oceania
  525. Octavia
  526. Olivia
  527. Ottavia
  528. Paige
  529. Pamela
  530. Paris
  531. Patience
  532. Patricia
  533. Paula
  534. Pearl
  535. Penelope
  536. Phoebe
  537. Phoenix
  538. Princess
  539. Priscilla
  540. Quinn
  541. Rachel
  542. Raina
  543. Raine
  544. Raven
  545. Rayna
  546. Raynee
  547. Rebecca
  548. Reece
  549. Reese
  550. Remi
  551. Remy
  552. Renee
  553. Rey
  554. Rhea
  555. Ria
  556. Riley
  557. Riva
  558. Rochelle
  559. Romina
  560. Romy
  561. Rosa
  562. Rosalie
  563. Rosalina
  564. Rosalind
  565. Rose
  566. Rosemary
  567. Rosetta
  568. Rosie
  569. Roxy
  570. Ruby
  571. Rylee
  572. Sabrina
  573. Sadie
  574. Samantha
  575. Sara
  576. Sarah
  577. Sasha
  578. Savannah
  579. Scarlet
  580. Scarlett
  581. Selena
  582. Serena
  583. Shannon
  584. Sharon
  585. Shayna
  586. Shea
  587. Shelby
  588. Shirley
  589. Sienna
  590. Sierra
  591. Silvia
  592. Simona
  593. Simone
  594. Sinead
  595. Skye
  596. Skylar
  597. Skyler
  598. Sofia
  599. Solei
  600. Sophia
  601. Sophie
  602. Stassi
  603. Stella
  604. Summer
  605. Susan
  606. Susanna
  607. Susannah
  608. Suzannah
  609. Suzanne
  610. Sydney
  611. Sylvia
  612. Tabitha
  613. Talia
  614. Tammy
  615. Tara
  616. Tatiana
  617. Teagan
  618. Terra
  619. Theodora
  620. Tia
  621. Tiana
  622. Tiffany
  623. Tori
  624. Tracy
  625. Trinity
  626. Trista
  627. Tulia
  628. Valentina
  629. Valentine
  630. Valeria
  631. Vanessa
  632. Venus
  633. Vera
  634. Veronica
  635. Victoria
  636. Vienna
  637. Viola
  638. Violet
  639. Violette
  640. Virginia
  641. Vita
  642. Vivian
  643. Viviana
  644. Vivienne
  645. Winona
  646. Xena
  647. Yasmin
  648. Yolanda
  649. Yvonne
  650. Zahara
  651. Zahra
  652. Zara
  653. Zelda
  654. Zoe
  655. Zoey
  656. Zoie
  657. Zola
  658. Zuri
  659. '''.splitlines()[1:-1]
  660.  
  661. # Add the names to our list
  662. update(names)
  663.  
  664. # Create a binding on the listbox onclick
  665. my_list.bind("<<ListboxSelect>>", fillout)
  666.  
  667. # Create a binding on the entry box
  668. my_entry.bind("<KeyRelease>", check)
  669.  
  670. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement