我有一个tkinter组合框,其中有1000个值。是否可以具有自动完成搜索功能?
就像我在组合框中键入内容一样,它应该执行一些通配符搜索并显示结果。
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)
您可以使用AutocompleteCombobox
来自tkentrycomplete
模块的方法。以下示例可以为您提供帮助。
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()
您可以在此处找到模块链接
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句