Source Code
Source Code
Import tkinter as tk
Try:
Conn = create_connection()
Cursor = conn.cursor()
Cursor.execute(“INSERT INTO books (book_name, quantity_available) VALUES
(%s, %s)”,
(book_name, quantity))
Conn.commit()
Messagebox.showinfo(“Success”, “Book added successfully”)
Conn.close()
Except Exception as e:
Messagebox.showerror(“Error”, f”Failed to insert book: {str€}”)
If data:
Books_window = tk.Toplevel()
Books_window.title(“All Books”)
Tree.pack(padx=10, pady=10)
Else:
Messagebox.showinfo(“No Data”, “No books found in the system.”)
Except Exception as e:
Messagebox.showerror(“Error”, f”Failed to fetch books: {str€}”)
# Lend a book
Def lend_book():
Def lend():
Borrower_name = borrower_name_entry.get()
Contact = contact_entry.get()
Book_name = book_name_entry.get()
Lend_date = datetime.now().strftime(“%Y-%m-%d %H:%M:%S”)
# Calculate the return date (for example, 7 days after the lend date)
Return_date = (datetime.now() + timedelta(days=7)).strftime(“%Y-%m-%d %H:
%M:%S”)
Try:
Conn = create_connection()
Cursor = conn.cursor()
Cursor.execute(“SELECT quantity_available FROM books WHERE book_name =
%s”, (book_name,))
Data = cursor.fetchone()
If data:
Lent_books_window = tk.Toplevel()
Lent_books_window.title(“Lent Books Details”)
Tree.pack(padx=10, pady=10)
Else:
Messagebox.showinfo(“No Data”, “No lent books found in the system.”)
Except Exception as e:
Messagebox.showerror(“Error”, f”Failed to fetch lent book details: {str€}”)
# Main Menu
Def main_menu():
Root = tk.Tk()
Root.title(“Library Management System”)
# Set the geometry to increase the height of the main window
Root.geometry(“800x500”) # Set the width and height of the window
# School name label with “Old English” font
School_label = tk.Label(root, text=”Montfort School Libarary”, font=(“Bookman Old
Style”, 30), padx=10, pady=10)
School_label.pack()
Root.mainloop()