-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch_box.py
72 lines (42 loc) · 1.2 KB
/
search_box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from Heema import *
root=Tk()
root.geometry("500x300+500+250")
#root.overrideredirect(True)
#title_bar=title_bar(root,text="Abhay")
def update(data):
#clear the listbox
my_list.delete(0,END)
#add toppings to list box
for item in data:
my_list.insert(END,item)
#update entry box with listbox clicked
def fillout(e):
#delet whatever is there in the list box
my_entry.delete(0,END)
my_entry.insert(0,my_list.get(ACTIVE))
#create a function ot check entry vs listbox
def check(e):
#grab what's typed:
typed= my_entry.get()
if typed=='':
data= toppings
else:
data=[]
for item in toppings:
if typed.lower() in item.lower():
data.append(item)
update(data)
label1=Label(root,text="start typing")
label1.pack()
#entry box:
my_entry=ttk.Entry(root)
my_entry.pack()
my_list=Listbox(root,width=50)
my_list.pack(pady=40)
toppings=["Pepperoni","Peppers","Mushrooms","Cheese","Onions","Ham","Taco"]
#add the toppings to our list
update(toppings)
#create a binding on the listbox onclick
my_list.bind("<<ListboxSelect>>",fillout) #for list boxes we use doube arrows
my_entry.bind("<KeyRelease>",check)
root.mainloop()