-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (49 loc) · 2.1 KB
/
main.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
from tkinter import *
# Read the file containing Dewey Decimal Subject Headings and
# corosponding numbers. Then index them in to a list to be
# searched later
file = open("DeweySubjectIndex.txt", "r")
content = file.read().split('\n')
def callback():
search_terms = search_box.get()
search_box.delete("0", END)
if len(search_terms) > 0:
results_list = []
for i in content:
if search_terms.lower() in i.lower():
if i not in results_list:
results_list.append(i + '\n')
Content_Text.delete("1.0", END)
if len(results_list) == 0:
Content_Text.insert("0.0", "No resutls found.")
elif len(results_list) > 10000:
Content_Text.insert("0.0", "Too many resutls found. Please narrow search terms.")
else:
for i in results_list:
Content_Text.insert('0.0', i)
else:
Content_Text.delete("1.0", END)
Content_Text.insert('0.0', "Please enter a search term.")
# Create an instance of tkinter.
root = Tk()
root.minsize(500, 250)
root.maxsize(800, 800)
root.title("Dewey Decimal Quick Reference")
# Create the frame to hold the search tools.
Search_Frame = Frame(root)
Search_Frame.pack(side='top')
Search_Label = Label(Search_Frame, text="Search Dewey Reference Numbers by Subject Keyword", font=("Times New Roman", 12))
Search_Label.pack(side='top')
# Create the search box.
search_box = Entry(Search_Frame, width=40, font=("Times New Roman", 12))
search_box.pack(side='left', padx=10)
# Create the search button.
s_button = Button(Search_Frame, text="Submit", font=("Times New Roman", 12), width=10, command=callback)
s_button.pack(side="right", padx=10)
#Create the frame in which content will be displayed.
Content_Frame = Frame(root)
Content_Frame.pack(side='bottom')
# Create the label that will display the search results.
Content_Text = Text(Content_Frame, relief='sunken', font=("Times New Roman", 14))
Content_Text.pack(side='bottom', fill='x', padx=10, pady=10)
root.mainloop()