-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistbox.py
More file actions
72 lines (57 loc) · 1.78 KB
/
listbox.py
File metadata and controls
72 lines (57 loc) · 1.78 KB
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 tkinter import *
def submit():
if(listbox.curselection()):
print("You have ordered: ")
# print(listbox.curselection())
# print(listbox.get(listbox.curselection()))
selectedFood = []
for index in listbox.curselection():
selectedFood.insert(index,listbox.get(index))
for f in selectedFood:
print(f)
else:
print("Nothing could be submitted!")
def add():
if(entryBox.get()!=""):
# listbox.insert(END,entryBox.get()) # add an item on the bottom
listbox.insert(0,entryBox.get()) # add an item on the top
listbox.config(height=listbox.size())
else:
print("Please enter an item.")
def delete():
# listbox.delete(listbox.curselection())
for index in listbox.curselection():
listbox.delete(index)
listbox.config(height=listbox.size())
food = ["pizza","pasta","garlic bread","soup","salad"]
window = Tk()
window.title("A listbox case")
listbox = Listbox(window,
bg='black',
fg='#00FF00',
font=("Arial",40),
width=30,
selectmode='multiple'
)
for index in range(len(food)):
listbox.insert(index,food[index])
listbox.pack()
listbox.config(height=listbox.size())
entryBox = Entry(window)
entryBox.pack()
addButton = Button(window,
text="add",
command=add
)
addButton.pack()
submit_button = Button(window,
text="submit",
command=submit
)
submit_button.pack()
deleteButton = Button(window,
text="delete",
command=delete
)
deleteButton.pack()
window.mainloop()