I have a tkinter combo box in which 1000s of values are there. Is it possible to have a autocomplete search feature in it?
Like if I type something in the combobox, it should perform some wildcard search and bring up the results.
element_names = list(**a very big list**)
dim_combo = ttk.Combobox(self, state='readonly')
dim_combo['values'] = self.element_names
dim_combo.place(x=100, y=100)
here is good solution :)
from tkinter import *
from tkinter import ttk
lst = ['C', 'C++', 'Java',
'Python', 'Perl',
'PHP', 'ASP', 'JS']
def check_input(event):
value = event.widget.get()
if value == '':
combo_box['values'] = lst
else:
data = []
for item in lst:
if value.lower() in item.lower():
data.append(item)
combo_box['values'] = data
root = Tk()
# creating Combobox
combo_box = ttk.Combobox(root)
combo_box['values'] = lst
combo_box.bind('<KeyRelease>', check_input)
combo_box.pack()
root.mainloop()
You can use the AutocompleteCombobox
method from tkentrycomplete
module. The below example can help you out.
import tkinter as tk
from tkinter import tkentrycomplete
root = tk.Tk()
box_value = tk.StringVar()
def fun():
print(box_value.get())
combo = tkentrycomplete.AutocompleteCombobox(textvariable=box_value)
test_list = ['apple', 'banana', 'cherry', 'grapes']
combo.set_completion_list(test_list)
combo.place(x=140, y=50)
button = tk.Button(text='but', command=fun)
button.place(x=140,y=70)
root.mainloop()
You can find the module here link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With