-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu.py
621 lines (554 loc) · 22 KB
/
menu.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# this file is the GUI that the user uses to interact with the program
# last modified 12/12/2019 by Student ID: B915247
from tkinter import *
import sys
import os
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
# the libraries and module that need to be imported
# in order to make the GUI function properly
window = Tk()
window.title("Library Logistics System")
window.geometry("2000x2000")
window.configure(background="black")
search_mes = Label(window, text="Please input the title of the book you are looking for", fg="white", bg="black")
return_mes = Label(window, text="Please input the ID of the book you want to return", fg="white", bg="black")
delete_mes = Label(window, text="Please input the tittle of the book you want to delete", fg="white", bg="black")
add_mes = Label(window, text="Please input the required information to add a new book", fg="white", bg="black")
co_mes = Label(window, text="Please input the book and student id", fg="white", bg="black")
co_member = Label(window, text="User ID:", fg="white", bg="black")
co_book = Label(window, text="Book ID:", fg="white", bg="black")
availability_mes = Label(window, text="Please write the title of the book you want to check", fg="white", bg="black")
# the initial step of the GUI declaring it includes the
# messages that come up after a button has been activated
# it also includes the title of the window and it's size
# every function also hides the button
# that are associated with different functions
def search():
# this function is activated when the search button is clicked
# this function shows up the search box, the button and a message explaining what to do
search_mes.place(relx=0.05, rely=0.23, anchor=NW)
searchbox.place(relx=0.05, rely=0.26, anchor=NW, height=25, width=150)
initialize_search.place(relx=0.15, rely=0.26, anchor=NW, height=25, width=50)
# closes all the widgets not associated with this function
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_book.place_forget()
co_member.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def search_pt2():
import booksearch
# this function is activated by the initialize_search
# button and does the search, if the title is true it outputs
# the results, otherwise it does nothing
input1 = searchbox.get()
data = booksearch.complete_search(input1)
print(data)
if data is not None:
search_result.config(text=data)
search_result.place(relx=0.5, rely=0.2, anchor=CENTER)
def killer():
# kills the entire program, activated by the quit button
quit()
window.quit()
def deletion():
# it is in charge of showing the deletion entry
# box and the the message explaining what to do as well as the
# button to submit the title
delete_mes.place(relx=0.05, rely=0.35, anchor=NW)
deletebox.place(relx=0.05, rely=0.38, anchor=NW, height=25, width=150)
initialize_del.place(relx=0.15, rely=0.38, anchor=NW, height=25, width=50)
# closes all the widgets not associated with this function
searchbox.place_forget()
initialize_search.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
add_mes.place_forget()
co_member.place_forget()
co_book.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def deletionpt2():
import booksearch
# it is in charge in testing if the title name submitted is correct
# if it is it shows an entry message and asks if the deletion should proceed
titledel = deletebox.get()
if titledel != '' and booksearch.complete_search(titledel) is not None:
# testing that the input is correct
inputm = "Is this the book you are looking for?"
message.config(text=inputm + '\n' + booksearch.complete_search(titledel))
transfer.config(text=titledel)
message.place(relx=0.5, rely=0.2, anchor=CENTER)
confirm_del.place(relx=0.4, rely=0.3, anchor=CENTER)
no_button.place(relx=0.6, rely=0.3, anchor=CENTER)
def deletionpt3():
import booksearch
# it executes the deletion and closes all boxes and search boxes
mes = transfer.cget("text")
booksearch.book_deletion(str(mes))
print(mes)
kill_all_hiden()
def addition():
# it is in charge of showing the addition entry box
# and the the message explaining what to do as well as the
# button to submit the title
add_mes.place(relx=0.05, rely=0.5, anchor=NW)
authorf.place(relx=0.02, rely=0.54, anchor=NW)
author.place(relx=0.05, rely=0.54, anchor=NW, height=25, width=100)
titlef.place(relx=0.02, rely=0.58, anchor=NW)
title.place(relx=0.05, rely=0.58, anchor=NW, height=25, width=100)
initialize_add.place(relx=0.05, rely=0.64, anchor=NW, height=25, width=50)
# closes all the widgets not associated with this function
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
co_member.place_forget()
co_book.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def additionpt2():
# it checks if the input is valide, the boxes were not empty.
# If it is, it reads the input and produces a
# warning message regarding if the addition should go ahead
authorin = author.get()
titlein = title.get()
if authorin != '' and titlein != '':
n = "%s | %s " % (titlein, authorin)
m = "%s by %s " % (titlein, authorin)
inputm = "Is this the book you are looking for"
transfer.config(text=n)
message.config(text=inputm + '\n' + m)
message.place(relx=0.5, rely=0.2, anchor=CENTER)
confirm_add.place(relx=0.4, rely=0.3, anchor=CENTER)
no_button.place(relx=0.6, rely=0.3, anchor=CENTER)
def additionpt3():
import booksearch
# it executes the book addition
mes = transfer.cget("text")
booksearch.book_insertor(mes)
print(mes)
kill_all_hiden()
def checkout():
# it is in charge of showing the checkout entry boxes
# and the the message explaining what to do as well as the
# button to submit the book and member's id
co_mes.place(relx=0.94, rely=0.43, anchor=E)
co_member.place(relx=0.84, rely=0.46, anchor=E)
co_mid.place(relx=0.88, rely=0.46, anchor=E, height=25, width=50)
co_book.place(relx=0.84, rely=0.5, anchor=E)
co_bid.place(relx=0.88, rely=0.5, anchor=E, height=25, width=50)
initialize_co.place(relx=0.95, rely=0.5, anchor=E, height=25, width=100)
# closes all the widgets not associated with this function
initialize_add.place_forget()
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
def checkoutpt2():
import bookcheckout
# it makes sure that input is correct and then loans the book
# if the loan is successful it outputs a message confirming that
# if not it does the exact same thing
# if the input is incorrect it does nothing
mid = co_mid.get()
bid = co_bid.get()
if mid != '' and bid != '' and len(mid) == 4 and str(mid).isdigit() and str(bid).isdigit():
x = bookcheckout.checkout(int(bid), int(mid))
if x:
checkout_final_mes.config(text="The book was successfully loaned")
else:
checkout_final_mes.config(text="The book is loaned")
checkout_final_mes.place(relx=0.5, rely=0.2, anchor=CENTER)
def return_book():
# it is in charge of showing the return entry box and the the message
# explaining what to do as well as the
# button to submit the book's id
return_mes.place(relx=0.98, rely=0.61, anchor=E)
return_entry.place(relx=0.885, rely=0.65, anchor=E, height=25, width=50)
initialize_return.place(relx=0.8945, rely=0.7, anchor=E, height=25, width=70)
# this part closes all the widgets not associated with return_book()
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
search_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_member.place_forget()
co_book.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
checkout_final_mes.place_forget()
def return_bookpt2():
import bookreturn
# it makes sure that input is correct and then returns the book
# if the return is successful it outputs a message confirming that
# if not it does the exact same thing
m = return_entry.get()
if m != '' and str(m).isdigit():
m = bookreturn.return_books(str(m))
if m:
return_final_mes.config(text="The book was successfully returned")
else:
return_final_mes.config(text="The book was not loaned")
return_final_mes.place(relx=0.5, rely=0.2, anchor=CENTER)
def popular():
import booklist
# it produces a graph that shows the top 10 most popular books
# in order to close the graph the small quit button needs to be pressed
# prepares the canvas and places it
fig = booklist.plotter()
pop = FigureCanvasTkAgg(fig, master=window)
pop.draw()
pop.get_tk_widget().place(relx=0.5, rely=0.5, anchor=CENTER, height=500, width=920)
def quitgraph():
pop.get_tk_widget().place_forget()
quit_graph.place_forget()
quit_graph = Button(window, text="quit", command=quitgraph)
quit_graph.place(relx=0.05, rely=0.78, anchor=NW, height=25, width=100)
# closes all the widgets not associated with this function
booklist.reformattor()
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_member.place_forget()
co_book.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def show_books():
import booksearch
# it shows all the books that the library has
present_books.config(text=booksearch.presenter())
present_books.place(relx=0.5, rely=0.5, anchor=CENTER)
# closes all the widgets not associated with this function
# your code
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_book.place_forget()
co_member.place_forget()
search_result.place_forget()
availability_mes.place_forget()
availability_entry.place_forget()
initialize_st.place_forget()
stres.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def availability():
# it is in charge of showing the availability entry box and the
# the message explaining what to do as well as the
# button to submit the book's title
availability_mes.place(relx=0.98, rely=0.23, anchor=E)
initialize_st.place(relx=0.9, rely=0.3, anchor=E, height=25, width=100)
availability_entry.place(relx=0.9, rely=0.26, anchor=E, height=25, width=100)
# closes all the widgets not associated with this function
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_member.place_forget()
co_book.place_forget()
search_result.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def availabilitypt2():
import booksearch
# it is in charge of checking if the input is correct if it exists and the field is not empty
# then it outputs a message that declares if the book is available or not
input1 = availability_entry.get()
data = booksearch.availability(input1)
if data and input1 != '':
stres.config(text='The book "%s" is available' % input1)
stres.place(relx=0.5, rely=0.2, anchor=CENTER)
elif data is False and input1 != '':
stres.config(text='The book "%s" is unavailable' % input1)
stres.place(relx=0.5, rely=0.2, anchor=CENTER)
def kill_all_hiden():
# it is charge of killing all the hidden widgets
searchbox.place_forget()
initialize_search.place_forget()
deletebox.place_forget()
initialize_del.place_forget()
initialize_add.place_forget()
co_mid.place_forget()
co_bid.place_forget()
initialize_co.place_forget()
return_entry.place_forget()
initialize_return.place_forget()
search_mes.place_forget()
return_mes.place_forget()
delete_mes.place_forget()
add_mes.place_forget()
co_book.place_forget()
co_member.place_forget()
search_result.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
datef.place_forget()
date.place_forget()
initialize_add.place_forget()
availability_mes.place_forget()
initialize_st.place_forget()
availability_entry.place_forget()
stres.place_forget()
add_mes.place_forget()
authorf.place_forget()
author.place_forget()
titlef.place_forget()
title.place_forget()
initialize_add.place_forget()
message.place_forget()
confirm_add.place_forget()
no_button.place_forget()
confirm_del.place_forget()
co_mes.place_forget()
present_books.place_forget()
return_final_mes.place_forget()
checkout_final_mes.place_forget()
def restart_the_program():
# it restarts the entire program, used to make sure that all systems behave accordingly
python = sys.executable
os.execl(python, python, * sys.argv)
# the entry buttons and fields of all the functions as well as the buttons that activate them
no_button = Button(window, text="Cancel", highlightcolor="Black", fg="Black", command=kill_all_hiden)
transfer = Label(window) # used in order to transfer values from one function to another
title = Label(window, text="Welcome to the Library management system", font=("Helvetica", 16), fg="white", bg="black")
title.place(relx=0.5, rely=0.05, anchor=CENTER)
search = Button(window, text="Search a title", highlightcolor="Black", fg="Black", command=search)
search.place(relx=0.05, rely=0.2, anchor=NW, height=25, width=100)
availabilityb = Button(window, text="Availability", highlightcolor="Black", command=availability)
availabilityb.place(relx=0.90, rely=0.2, anchor=E, height=25, width=100)
quitter = Button(window, text="Quit", command=killer)
quitter.place(relx=0.05, rely=0.05, anchor=NW, height=25, width=100)
deleteb = Button(window, text="Delete a title", command=deletion)
deleteb.place(relx=0.05, rely=0.32, anchor=NW, height=25, width=100)
confirm_del = Button(window, text="Confirm", command=deletionpt3)
importb = Button(window, text="Add a book", command=addition)
importb.place(relx=0.05, rely=0.46, anchor=NW, height=25, width=100)
checkoutb = Button(window, text="Check Out", command=checkout)
checkoutb.place(relx=0.90, rely=0.4, anchor=E, height=25, width=100)
returnb = Button(window, text="Return a Book", command=return_book)
returnb.place(relx=0.9, rely=0.57, anchor=E, height=25, width=100)
popularb = Button(window, text="Popularity ratings", command=popular)
popularb.place(relx=0.05, rely=0.75, anchor=NW, height=25, width=100)
bookb = Button(window, text="See all books", command=show_books)
bookb.place(relx=0.90, rely=0.75, anchor=E, height=25, width=100)
present_books = Label(window, font=18, fg="white", bg="black")
searchbox = Entry(window)
initialize_search = Button(window, text="Search", highlightcolor="Black", fg="Black", command=search_pt2)
search_result = Label(window, font=16, fg="white", bg='black')
initialize_del = Button(window, text="Delete", highlightcolor="Black", fg="Black", command=deletionpt2)
deletebox = Entry(window)
initialize_add = Button(window, text="Add", highlightcolor="Black", fg="Black", command=additionpt2)
author = Entry(window)
authorf = Label(window, text="Author:", fg="white", bg='black')
title = Entry(window)
titlef = Label(window, text="Title:", fg="white", bg='black')
date = Entry(window)
datef = Label(window, text="Date:", fg="white", bg='black')
confirm_add = Button(window, text="Yes", highlightcolor="Black", fg="Black", command=additionpt3)
message = Label(window, font=16, fg="Black", bg="black")
initialize_co = Button(window, text="Check-Out", highlightcolor="Black", fg="Black", command=checkoutpt2)
co_mid = Entry(window)
co_bid = Entry(window)
checkout_final_mes = Label(window, font=16, fg="white", bg='black')
initialize_return = Button(window, text="Return", highlightcolor="Black", fg="Black", command=return_bookpt2)
return_entry = Entry(window)
return_final_mes = Label(window, font=16, fg="white", bg='black')
initialize_st = Button(window, text="Check", highlightcolor="Black", fg="Black", command=availabilitypt2)
stres = Label(window, font=16, fg="white", bg="black")
availability_entry = Entry(window)
restart = Button(window, text="Restart", highlightcolor="Black", fg="Black", command=restart_the_program)
restart.place(relx=0.83, rely=0.05, anchor=NW, height=25, width=100)
window.mainloop()