class GUI: def __init__(self, master): self.parent = master self.parent.title(" Library Management System ") self.frame = Frame(self.parent, bg='yellow', width=800, height=400) self.frame.grid(row=0, column=0) self.frame.grid_rowconfigure(0, weight=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_propagate(False) # Parameter Initialization self.search_string = None self.data = None self.borrower_id = None self.book_for_check_out_isbn = None # Heading grid self.heading_label = Frame(self.frame, bg='yellow') self.heading_label.grid(row=0, column=0, sticky=N) self.heading_label.grid_rowconfigure(0, weight=1) self.heading_label.grid_columnconfigure(0, weight=1) self.heading_label = Label(self.heading_label,bg='yellow', text='Library Management System', font=('Helvetica',15)) self.heading_label.grid(row=0, column=0) self.heading_label.grid_rowconfigure(0, weight=1) self.heading_label.grid_columnconfigure(0, weight=1) #search frame grid self.search_frame = Frame(self.frame, bg='yellow') self.search_frame.grid(row=1, column=0, sticky=W+E, padx=10, pady=10) self.search_frame.grid_rowconfigure(1, weight=1) self.search_frame.grid_columnconfigure(0, weight=1) self.search_label = Label(self.search_frame, text='Search here :', bg='yellow') self.search_label.grid(row=1, column=0, sticky=N+S+W, padx=10, pady=10) self.search_label.grid_rowconfigure(1, weight=1) self.search_label.grid_columnconfigure(0, weight=1) self.search_textbox = Entry(self.search_frame, width=65) self.search_textbox.grid(row=1, column=0, sticky=N+S, padx=10, pady=10) self.search_textbox.grid_rowconfigure(1, weight=1) self.search_label.grid_columnconfigure(0, weight=1) self.search_button = Button(self.search_frame, text='Search / View All',bg='blue',fg='white', command=self.search) self.search_button.grid(row=1, column=0, sticky=N+S+E, padx=10, pady=10) self.search_button.grid_rowconfigure(1, weight=1) self.search_button.grid_columnconfigure(0, weight=1) # Display Area grid self.active_area = Frame(self.frame) self.active_area.grid(row=2, column=0, sticky=N) self.active_area.grid_rowconfigure(2, weight=0) self.result_table = Treeview(self.active_area, columns=["isbn", "Book Title", "Author(s)", "Availability"]) self.result_table.grid(row=0, column=0) self.result_table.grid_rowconfigure(0, weight=0) self.result_table.heading('#0', text="isbn") self.result_table.heading('#1', text="Book Title") self.result_table.heading('#2', text="Author(s)") self.result_table.heading('#3', text="Availability") self.result_table.bind('<ButtonRelease-1>', self.selectBookForCheckout) # Buttons grid self.major_functions = Frame(self.frame, bg='yellow') self.major_functions.grid(row=3, column=0, sticky=N) self.major_functions.grid_rowconfigure(3, weight=1) self.check_out_btn = Button(self.major_functions, text="Check Out Book",bg='blue',fg='white', command=self.check_out_fn) self.check_out_btn.grid(row=0, column=0, padx=10, pady=10) self.check_out_btn.grid_rowconfigure(0, weight=1) self.check_out_btn.grid_columnconfigure(0, weight=1) self.check_in_btn = Button(self.major_functions, text="Check In Book",bg='blue',fg='white', command=self.check_in_fn) self.check_in_btn.grid(row=0, column=1, padx=10, pady=10) self.check_out_btn.grid_rowconfigure(0, weight=1) self.check_out_btn.grid_columnconfigure(1, weight=1) self.update_fines_btn = Button(self.major_functions, text="Updates Fines",bg='blue',fg='white', command=self.update_fines_fn) self.update_fines_btn.grid(row=0, column=2, padx=10, pady=10) self.pay_fines_btn = Button(self.major_functions, text="Pay Fines",bg='blue',fg='white', command=self.pay_fines) self.pay_fines_btn.grid(row=0, column=3, padx=10, pady=10) self.change_day_btn = Button(self.major_functions, text="Change Day",bg='blue',fg='white', command=self.change_day) self.change_day_btn.grid(row=0, column=4, padx=10, pady=10) self.add_borrower_btn = Button(self.major_functions, text="Add New Borrower",bg='blue',fg='white', command=self.add_borrower) self.add_borrower_btn.grid(row=0, column=5, padx=10, pady=10) def change_day(self): global todays_date todays_date = todays_date + timedelta(days=1) messagebox.showinfo("", "Date Changed ") #print(todays_date) def search(self): self.search_string = self.search_textbox.get() cursor = my_conn.cursor() cursor.execute("select book.isbn, book.title, authors.name from book join book_authors on book.isbn = book_authors.isbn join authors on book_authors.author_id = authors.author_id where book.title ilike concat('%', '" + self.search_string + "', '%') OR authors.name ilike concat('%', '" + self.search_string + "', '%') OR book.isbn ilike concat('%', '" + self.search_string + "', '%')") self.data = cursor.fetchall() self.view_data() def view_data(self): self.result_table.delete(*self.result_table.get_children()) for elem in self.data: cursor = my_conn.cursor() cursor.execute("select exists(select book_loans.isbn from book_loans where book_loans.isbn = '" + str(elem[0]) + "')") result = cursor.fetchall() if result == [(0,)]: availability = "Available" else: cursor = my_conn.cursor() cursor.execute("select book_loans.date_in from book_loans where book_loans.isbn = '" + str(elem[0]) + "'") result = cursor.fetchall() if result[-1][0] is None: availability = "Not Available" else: availability = "Available" self.result_table.insert('', 'end', text=str(elem[0]), values=(elem[1], elem[2], availability)) def selectBookForCheckout(self, a): curItem = self.result_table.focus() self.book_for_check_out_isbn = self.result_table.item(curItem)['text'] def check_out_fn(self): if self.book_for_check_out_isbn is None: messagebox.showinfo("", "Select Book") return None cursor = my_conn.cursor() cursor.execute("select exists(select isbn from book_loans where isbn ilike '" + self.book_for_check_out_isbn + "' and date_in is NULL) ") result = cursor.fetchall() print(result) if result == [(1,)]: messagebox.showinfo(" ", "Book not Available") return None self.borrower_id = simpledialog.askstring("Check Out Book", "Enter Borrower ID") cursor = my_conn.cursor() cursor.execute("select exists(select card_id from borrower where borrower.card_id = '" + str(self.borrower_id) + "')") result = cursor.fetchall() if int(self.borrower_id) > 1000 + borrower_count: messagebox.showinfo(" ", "Borrower not in Database!") return None else: count = 0 cursor = my_conn.cursor() cursor.execute("select book_loans.date_in from book_loans where book_loans.card_id = '" + str(self.borrower_id) + "'") result = cursor.fetchall() for elem in result: if elem[0] is None: count += 1 if count >= 3: messagebox.showinfo(" ", "Borrower has loaned 3 books already!") return None else: cursor = my_conn.cursor() cursor.execute("insert into book_loans (isbn, card_id, date_out, due_date) VALUES (%s, %s , current_date , current_date + 14)" , ( self.book_for_check_out_isbn , self.borrower_id) ) my_conn.commit() cursor = my_conn.cursor() cursor.execute("select MAX(loan_id) from book_loans") result = cursor.fetchall() loan_id = result[0][0] cursor.execute("insert into fines (loan_id, fine_amt, paid) VALUES ('" + str(loan_id) + "', '0.00', '0')") my_conn.commit() messagebox.showinfo(" ", "Book Loaned Out!") def check_in_fn(self): self.checkInWindow = Toplevel(self.parent, width=500, height=200, bg='yellow') self.checkInWindow.title("Check In Here") self.app = CheckIn(self.checkInWindow) def update_fines_fn(self): cursor = my_conn.cursor() cursor.execute("select book_loans.loan_id, book_loans.date_in, book_loans.due_date from book_loans") result = cursor.fetchall() for record in result: date_in = record[1] due_date = record[2] if date_in is None: date_in = todays_date.date() diff = date_in - due_date if diff.days > 0: fine = int(diff.days) * 0.25 else: fine = 0 cursor = my_conn.cursor() cursor.execute("update fines set fine_amt = %s where fines.loan_id = %s", (fine, record[0])) my_conn.commit() messagebox.showinfo(" ","Fines Calculated") def pay_fines(self): self.newPayFinesWindow = Toplevel(self.parent, bg='yellow') self.newPayFinesWindow.title("Pay Fines") self.app1 = PayFines(self.newPayFinesWindow) def add_borrower(self): self.newBorrowerWindow = Toplevel(self.parent, bg='yellow') self.newBorrowerWindow.title("Add New Borrower") self.newapp = AddBorrower(self.newBorrowerWindow)
class MainGUI: def __init__(self, master): self.parent = master # Set frame for the whole thing self.parent.title("LMS") self.frame = Frame(self.parent, width=1500, height=750) self.frame.grid(row=0, column=0) self.frame.grid_rowconfigure(0, weight=1) self.frame.grid_columnconfigure(0, weight=1) self.frame.grid_propagate(False) # Parameter Initialization self.search_string = None self.data = None self.borrowerId = None self.bookForCheckOutIsbn = None # Frame for the welcome message and header self.HeaderFrame = Frame(self.frame) self.HeaderFrame.grid(row=0, column=0, sticky=N) self.HeaderFrame.grid_rowconfigure(0, weight=1) self.HeaderFrame.grid_columnconfigure(0, weight=1) # # Label for the welcome message self.HeaderLabel = Label(self.HeaderFrame, text='What Book Do You Want?') self.HeaderLabel.grid(row=0, column=0) self.HeaderLabel.grid_rowconfigure(0, weight=10) self.HeaderLabel.grid_columnconfigure(0, weight=10) #Label for the searchbox self.SearchLabel = Label(self.HeaderFrame, text='') self.SearchLabel.grid(row=1, column=0) self.SearchLabel.grid_rowconfigure(1, weight=10) self.SearchLabel.grid_columnconfigure(0, weight=10) # Search Frame self.SearchFrame = Frame(self.frame) self.SearchFrame.grid(row=1, column=0, sticky=N) self.SearchFrame.grid_rowconfigure(1, weight=1) # self.SearchFrame.grid_columnconfigure(0, weight=1) self.SearchLabel = Label(self.SearchFrame, text='Search') self.SearchLabel.grid(row=0, column=0) self.SearchLabel.grid_rowconfigure(0, weight=1) # self.SearchLabel.grid_columnconfigure(0, weight=1) self.SearchTextBox = Entry(self.SearchFrame, text='Enter search string here...', width=70) self.SearchTextBox.grid(row=1, column=0) self.SearchTextBox.grid_rowconfigure(1, weight=1) self.SearchButton = Button(self.SearchFrame, text='Search', command=self.search) self.SearchButton.grid(row=2, column=0) self.SearchButton.grid_rowconfigure(2, weight=1) # Search Result Frame self.ActiveArea = Frame(self.frame) self.ActiveArea.grid(row=2, column=0, sticky=N) self.ActiveArea.grid_rowconfigure(2, weight=1) self.ResultTreeview = Treeview( self.ActiveArea, columns=["ISBN", "Book Title", "Author(s)", "Availability"]) self.ResultTreeview.grid(row=1, column=1) self.ResultTreeview.grid_rowconfigure(0, weight=1) self.ResultTreeview.heading('#0', text="ISBN") self.ResultTreeview.heading('#1', text="Book Title") self.ResultTreeview.heading('#2', text="Author(s)") self.ResultTreeview.heading('#3', text="Availability") self.ResultTreeview.bind('<ButtonRelease-1>', self.selectBookForCheckout) # Interaction Frame self.MajorFunctions = Frame(self.frame) self.MajorFunctions.grid(row=3, column=0, sticky=N) self.MajorFunctions.grid_rowconfigure(3, weight=1) self.checkOutBtn = Button(self.MajorFunctions, text="Check Out Book", command=self.check_out) self.checkOutBtn.grid(row=0, column=0, padx=10, pady=10) self.checkOutBtn.grid_rowconfigure(0, weight=1) self.checkOutBtn.grid_columnconfigure(0, weight=1) self.checkInBtn = Button(self.MajorFunctions, text="Check In Book", command=self.check_in) self.checkInBtn.grid(row=0, column=1, padx=10, pady=10) self.checkOutBtn.grid_rowconfigure(0, weight=1) self.checkOutBtn.grid_columnconfigure(1, weight=1) self.updateFinesBtn = Button(self.MajorFunctions, text="Updates Fines", command=self.update_fines) self.updateFinesBtn.grid(row=1, column=0, padx=10, pady=10) self.payFinesBtn = Button(self.MajorFunctions, text="Pay Fines", command=self.pay_fines) self.payFinesBtn.grid(row=1, column=1, padx=10, pady=10) self.changeDayBtn = Button(self.MajorFunctions, text="Change Day", command=self.change_day) self.changeDayBtn.grid(row=1, column=2, padx=10, pady=10) self.addBorrowerBtn = Button(self.MajorFunctions, text="Add New Borrower", command=self.add_borrower) self.addBorrowerBtn.grid(row=0, column=2, padx=10, pady=10) def change_day(self): global todays_date todays_date = todays_date + timedelta(days=1) print(todays_date) def search(self): self.search_string = self.SearchTextBox.get() cursor = cnx.cursor() cursor.execute( "select BOOK.isbn, BOOK.title, AUTHORS.fullname from BOOK join BOOK_AUTHORS on " "BOOK.isbn = BOOK_AUTHORS.isbn join AUTHORS on BOOK_AUTHORS.author_id = AUTHORS.author_id " "where BOOK.title like concat('%', '" + self.search_string + "', '%') or " "AUTHORS.fullname like concat('%', '" + self.search_string + "', '%') or " "BOOK.isbn like concat('%', '" + self.search_string + "', '%')") self.data = cursor.fetchall() self.view_data() def view_data(self): """ View data on Treeview method. """ self.ResultTreeview.delete(*self.ResultTreeview.get_children()) for elem in self.data: cursor = cnx.cursor() cursor.execute( "SELECT EXISTS(SELECT BOOK_LOANS.isbn from BOOK_LOANS where BOOK_LOANS.isbn = '" + str(elem[0]) + "')") result = cursor.fetchall() if result == [(0, )]: availability = "Available" else: cursor = cnx.cursor() cursor.execute( "SELECT BOOK_LOANS.Date_in from BOOK_LOANS where BOOK_LOANS.isbn = '" + str(elem[0]) + "'") result = cursor.fetchall() if result[-1][0] is None: availability = "Not Available" else: availability = "Available" self.ResultTreeview.insert('', 'end', text=str(elem[0]), values=(elem[1], elem[2], availability)) def selectBookForCheckout(self, a): curItem = self.ResultTreeview.focus() self.bookForCheckOutIsbn = self.ResultTreeview.item(curItem)['text'] def check_out(self): if self.bookForCheckOutIsbn is None: messagebox.showinfo("Attention!", "Select Book First!") return None self.borrowerId = simpledialog.askstring("Check Out Book", "Enter Borrower ID") cursor = cnx.cursor() cursor.execute( "SELECT EXISTS(SELECT Card_no from BORROWERS WHERE BORROWERS.Card_no = '" + str(self.borrowerId) + "')") result = cursor.fetchall() if result == [(0, )]: messagebox.showinfo("Error", "Borrower not in Database!") return None else: count = 0 cursor = cnx.cursor() cursor.execute( "SELECT BOOK_LOANS.Date_in from BOOK_LOANS WHERE BOOK_LOANS.Card_no = '" + str(self.borrowerId) + "'") result = cursor.fetchall() for elem in result: if elem[0] is None: count += 1 if count >= 3: messagebox.showinfo("Not Allowed!", "Borrower has loaned 3 books already!") return None else: cursor = cnx.cursor() cursor.execute("SET FOREIGN_KEY_CHECKS=0") cursor.execute( "INSERT INTO BOOK_LOANS (ISBN, Card_no, Date_out, Due_date) VALUES ('" + self.bookForCheckOutIsbn + "', '" + self.borrowerId + "', '" + str(todays_date) + "', '" + str(todays_date + timedelta(days=14)) + "')") cursor.execute("SET FOREIGN_KEY_CHECKS=1") cnx.commit() cursor = cnx.cursor() cursor.execute("SELECT MAX(Loan_Id) FROM BOOK_LOANS") result = cursor.fetchall() loan_id = result[0][0] cursor.execute( "INSERT INTO FINES (Loan_Id, fine_amt, paid) VALUES ('" + str(loan_id) + "', '0.00', '0')") cnx.commit() messagebox.showinfo("Done", "Book Loaned Out!") def check_in(self): self.checkInWindow = Toplevel(self.parent) self.checkInWindow.title("Check In Here") self.app = CheckIn(self.checkInWindow) def update_fines(self): cursor = cnx.cursor() cursor.execute( "SELECT BOOK_LOANS.Loan_Id, BOOK_LOANS.Date_in, BOOK_LOANS.Due_date FROM BOOK_LOANS" ) result = cursor.fetchall() for record in result: date_in = record[1] date_due = record[2] if date_in is None: date_in = todays_date diff = date_in.date() - date_due.date() if diff.days > 0: fine = int(diff.days) * 0.25 else: fine = 0 cursor = cnx.cursor() cursor.execute("UPDATE FINES SET FINES.fine_amt = '" + str(fine) + "' WHERE FINES.Loan_Id = '" + str(record[0]) + "'") cnx.commit() messagebox.showinfo("Info", "Generated Fines") def pay_fines(self): self.newPayFinesWindow = Toplevel(self.parent) self.newPayFinesWindow.title("Fine!!") self.app1 = PayFines(self.newPayFinesWindow) def add_borrower(self): self.newBorrowerWindow = Toplevel(self.parent) self.newBorrowerWindow.title("Borrowing Person New") self.newapp = BorrowingPerson(self.newBorrowerWindow)
tv.heading('temperature', text='Temperature') tv.column('temperature', anchor='center', width=95) tv.heading('light', text='Light') tv.column('light', anchor='center', width=65) tv.heading('soil', text='Soil') tv.column('soil', anchor='center', width=50) tv.heading('rainfall', text='Rainfall') tv.column('rainfall', anchor='center', width=75) tv.heading('land', text='Land', anchor=W) tv.column('land', anchor=W, width=75) #tv.grid(row=10,column=0,sticky = (N,S,W,E)) tv.config(height=1) #tv.tag_configure('test',background='red') tv.grid(row=10, columnspan=3) tv.grid_rowconfigure(10, weight=1) label2.grid(row=13, column=1) """ lb.grid(row=15,column=1) lb.config(height=10) for i in range(100): lb.insert(END, i) lb.config(yscrollcommand=scrollbar.set) scrollbar.config(command=lb.yview) """ tv2['columns'] = ('area', 'n', 'p', 'k') #tv['columns'] = ('starttime', 'endtime', 'status') tv2.heading("#0", text='Crop', anchor='center')