-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChoice_2.py
61 lines (54 loc) · 1.91 KB
/
Choice_2.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
from tkinter import *
from function import *
from data import *
import tkinter.scrolledtext as ScrolledText
def clear():
for widget in F.winfo_children():
widget.destroy()
def result():
clear()
lower_str = E1.get()
higher_str = E2.get()
for widget in F.winfo_children():
widget.destroy()
try:
higher = float(higher_str)
lower = float(lower_str)
if lower < 0:
l3 = Label(F, text="Wrong value! Please retry")
l3.pack()
elif higher>10:
l3 = Label(F, text="Wrong value! Please retry")
l3.pack()
elif lower>higher:
l3 = Label(F, text="Wrong value! Please retry")
l3.pack()
else:
price = (lower,higher)
food_list = search_by_price(price,price_canteens)
try:
st = ScrolledText.ScrolledText(F)
st.grid(sticky=W+E)
for item in food_list:
st.insert(END, item+'\n')
print(st.get(1.0, END))
except TypeError:
Label(F, text="No corresponding food!").grid(sticky='n')
Button(F, text='close', command=new_root.destroy).grid(sticky='s')
except ValueError:
l=Label(F, text="Wrong data type! Please retry")
l.pack()
new_root = Tk()
new_root.title("SEARCH FOOD BY PRICE")
L1 = Label(new_root, text="Please enter number from 0 to 10.").grid(row=0, columnspan=2)
L2 = Label(new_root, text="Lowest Price:").grid(row=1,column=0)
E1 = Entry(new_root, bd=5)
E1.grid(row=1,column=1)
L3 = Label(new_root, text="Highest Price:").grid(row=2,column=0)
E2 = Entry(new_root, bd=5)
E2.grid(row=2,column=1)
B1 = Button(new_root, text="search", command=result).grid(row=3,column=0)
B2 = Button(new_root, text="quit", command=new_root.destroy).grid(row=3,column=1)
F = Frame(new_root)
F.grid(row=4, column=0, columnspan=2)
new_root.mainloop()