Is it possible to create a combobox that updates with the closest item in its list as you type into it?
For example:
A = ttk.Combobox()
A['values'] = ['Chris', 'Jane', 'Ben', 'Megan']
Then you type "Chr" into the combobox, I want it to automatically fill in "Chris".
Use ttk. Combobox(root, textvariable) to create a combobox. Set the state property to readonly to prevent users from entering custom values. A combobox widget emits the '<<ComboboxSelected>>' event when the selected value changes.
textvariable. A variable linked to the current value of the combobox; when the variable is changed, the current value of the combobox will be updated, while when the user changes the combobox, the variable will be updated. values.
The Tkinter Combobox is one of the UI widgets in the Tkinter library and it is used for to select the values in the drop-down list column also it is one of the combinations of Entry and drop-down widgets these drop-down entries are replaceable one and the user if suppose not select the value in the box it automatically ...
The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, including macOS, as well as on Windows systems.
Yes, it can be easily done using the following example, taken from here:
from ttkwidgets.autocomplete import AutocompleteEntry
from tkinter import *
countries = [
'Antigua and Barbuda', 'Bahamas','Barbados','Belize', 'Canada',
'Costa Rica ', 'Cuba', 'Dominica', 'Dominican Republic', 'El Salvador ',
'Grenada', 'Guatemala ', 'Haiti', 'Honduras ', 'Jamaica', 'Mexico',
'Nicaragua', 'Saint Kitts and Nevis', 'Panama ', 'Saint Lucia',
'Saint Vincent and the Grenadines', 'Trinidad and Tobago', 'United States of America'
]
ws = Tk()
ws.title('PythonGuides')
ws.geometry('400x300')
ws.config(bg='#f25252')
frame = Frame(ws, bg='#f25252')
frame.pack(expand=True)
Label(
frame,
bg='#f25252',
font = ('Times',21),
text='Countries in North America '
).pack()
entry = AutocompleteEntry(
frame,
width=30,
font=('Times', 18),
completevalues=countries
)
entry.pack()
ws.mainloop()
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