MKH SANCHETI PUBLIC SCHOOL
KhasraNo:50/3-50/7GotadPanjri,BesaNagpur-440037 CBSE
AFFILIATION NO: 1130662
Practical/Project Work in Computer Science
Session 2024-25
All India Senior School Certificate Examination
Submitted By
Varun Tembhare and Saksham Junghare
CERTIFICATE
This is to certify that Varun Tembhare and Saksham Junghare of
Class XII has taken keen interest and with utmost sincerity
successfully completed this practical/project of Computer Science
under my supervision .This practical/project is a part of the CBSE
syllabus in the academic session 2024- 25.
Principal InternalExaminer/ProjectMentor
ExternalExaminer
ACKNOWLEDGEMENT
I would like to convey my heartfelt thanks to all my faculty
members who always gave valuable suggestions and guidance
during the completion of my practical/project. They helped me to
under standard remember important details of the practical/project.
My practical/ project has been a success only because of their
guidance.
Name:
RollNo:
Table of Contents
• Certificate
• Acknowledgment
• Introduction of Project
• Hardware and Software Requirements
• About the Programming Language
• Constructs used in Project
• Coding
• Output
• Bibliography
Introduction
The Library Management System is a Python-based application developed to
automate and simplify library operations. This system manages essential tasks
such as adding and viewing books, issuing and returning them, and maintaining
records of borrowing history. By utilizing SQLite as the database, the system
ensures efficient and accurate storage of data, making it a reliable solution for
library management.
The project eliminates the need for manual processes, reducing paperwork and
human errors. It features a user-friendly graphical interface built with Python's
Tkinter, allowing librarians and users to interact with the system easily. This
software is designed to save time and enhance the overall efficiency of library
operations.
The primary objective of this project is to provide a practical solution to real-
world challenges faced in library management. By replacing traditional methods
with an automated system, libraries can streamline their processes, improve
record-keeping, and deliver better services to their users. The system is suitable
for school libraries, small institutions, or any setup that requires simple and
effective library management.
Hardware and Software Requirements
Hardwares
1.DesktopComputer/Laptop
2.MobilePhone
Softwares
1.Python (LatestVersion)
2.MySQL
MySQL-Connector-Python, Requests ,Wikipedia-API, Datetime, Pyfiglet
Modules
About the Programming Language
1. Introduction to Python
Python is a high-level, versatile programming language known for its simplicity and
readability. It supports multiple programming paradigms, including procedural,
object-oriented, and functional programming. Python’s extensive libraries and
frameworks make it a popular choice for developing applications in various domains,
such as web development, data analysis, artificial intelligence, and system
automation.
In this project, Python is used to develop the Library Management System,
incorporating both a graphical user interface (GUI) and database connectivity. The
simplicity of Python's syntax enhances code readability and accelerates development.
2. Uses of Python in the Project
Database Management: The project uses the sqlite3 library to connect and interact
with an SQLite database. Python allows seamless execution of SQL commands for
tasks like creating tables, inserting records, and retrieving data.
Graphical User Interface (GUI): The Tkinter library in Python provides a user-
friendly interface for managing library operations. It enables features like buttons,
input fields, and message boxes for intuitive interaction.
Error Handling: Python’s built-in exception handling ensures that the program can
handle user errors, such as invalid inputs, gracefully.
Data Processing: Python simplifies reading, writing, and updating the records stored
in the database.
3. Functions in the Project
Functions are reusable blocks of code that perform specific tasks. This project
heavily utilizes functions for modularity and better code organization. Some key
functions used include:
setup_database (): Creates the necessary database tables if they do not exist.
add_book (title, author, copies): Adds a new book to the library database.
view_books : Retrieves and displays all books from the database.
issue_book (book_id, student_name, issue_date): Issues a book to a student, reducing
the available copies by one.
return_book (issue_id, return_date): Handles the return process and updates the
database.
These functions promote reusability and make the program easier to maintain.
4. Loops Used in the Project
The project uses loops, particularly for loops, to handle repetitive tasks, such as
displaying records. For example:
Displaying Data: When showing all books or issued books, a for loop iterates
through the fetched rows from the database and displays them in the
GUI.ConstructsUsedinthisProgram
Constructs Used in this Program
Conditional Statements
Conditional statements in Python, such as if and else, are used to control the
program flow based on specific conditions. In this project, they are employed to
validate user inputs and handle scenarios like book availability or invalid
operations.
Loops
Loops are used to perform repetitive tasks, such as displaying all records fetched
from the database.
For Loop: This loop iterates through the rows of data retrieved from the database
and dynamically updates the GUI.
Functions
Functions are the core building blocks of the program, used to encapsulate
reusable logic. This project defines multiple functions to handle specific tasks,
making the code modular and easy to maintain.
Exception Handling
Python’s try-except construct is used to handle errors gracefully. This ensures
that invalid operations, such as database connection errors or invalid inputs, do
not crash the program.
GUI Components
The program uses constructs from the Tkinter library to create and manage the
graphical user interface. These constructs include:
Frames: To organize the layout.
Labels: To display text.
Entry Fields: For user input.
Buttons: To trigger actions like adding or issuing books.
Database Interaction
The project interacts with the SQLite database using SQL commands embedded
in Python. Constructs like cursor.execute and fetchall are used to send queries
and retrieve data.
Databases Used in Program
1.Type of Database
The program uses SQLite, a lightweight and self-contained relational database
management system. SQLite is an excellent choice for small-scale applications
as it does not require a separate server or complex configurations. The database
is stored in a file (library.db), making it portable and easy to manage.
2.Tables in the Database
The program uses two primary tables to manage data:
Books Table:
Purpose: Stores information about the books available in the library.
Columns:
BookID (INTEGER, Primary Key): A unique identifier for each book.
Title (TEXT): The name of the book.
Author (TEXT): The author's name.
Copies (INTEGER): The number of copies available.
3.IssuedBooks Table:
Purpose: Keeps track of books that have been issued to students.
Columns:
IssueID (INTEGER, Primary Key): A unique identifier for each issued record.
BookID (INTEGER, Foreign Key): The ID of the book issued.
StudentName (TEXT): The name of the student who borrowed the book.
IssueDate (TEXT): The date when the book was issued.
ReturnDate (TEXT): The date when the book was returned (can be NULL)
4.Database Operations
The program performs the following operations on the database using Python’s
sqlite3 library:
Insert Records: Adds new books or issued book details into the respective tables.
Retrieve Records: Fetches data to display available books or issued books.
Update Records: Modifies data, such as updating the number of available copies
when a book is issued or returned.
Delete Records: Deletes issued book records upon return.
5.Advantages of Using SQLite
Lightweight: Ideal for local and small-scale applications like this project.
No Configuration Required: The database is created automatically as a file
without the need for a dedicated server.
Portability: The database file can be easily shared or moved with the application.
Reliability: Ensures data consistency with ACID (Atomicity, Consistency,
Isolation, Durability) compliance.
6.Database File
The database file for this project is named library.db. It is created automatically
when the program is run for the first time, and all data is stored within this file.
Coding
# Library Management System
# Developed using Python and SQLite
import sqlite3
from tkinter import *
from tkinter import messagebox
# Database Setup
def setup_database():
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Books (
BookID INTEGER PRIMARY KEY
AUTOINCREMENT,
Title TEXT NOT NULL,
Author TEXT NOT NULL,
Copies INTEGER NOT NULL
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS Students
(
StudentID INTEGER PRIMARY KEY
AUTOINCREMENT,
Name TEXT NOT NULL,
Class TEXT NOT NULL
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS
IssuedBooks (
IssueID INTEGER PRIMARY KEY
AUTOINCREMENT,
BookID INTEGER NOT NULL,
StudentID INTEGER NOT NULL,
IssueDate TEXT NOT NULL,
ReturnDate TEXT,
FOREIGN KEY (BookID) REFERENCES
Books(BookID),
FOREIGN KEY (StudentID)
REFERENCES Students(StudentID)
)''')
conn.commit()
conn.close()
# Add Book to Database
def add_book(title, author, copies):
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO Books (Title, Author,
Copies) VALUES (?, ?, ?)", (title, author, copies))
conn.commit()
conn.close()
messagebox.showinfo("Success", "Book added
successfully!")
# View Books
def view_books():
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
cursor.execute("SELECT * FROM Books")
books = cursor.fetchall()
conn.close()
return books
# Issue Book
def issue_book(book_id, student_id, issue_date):
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
cursor.execute("SELECT Copies FROM Books WHERE BookID
= ?", (book_id,))
book = cursor.fetchone()
if book and book[0] > 0:
cursor.execute("INSERT INTO IssuedBooks (BookID,
StudentID, IssueDate) VALUES (?, ?, ?)",
(book_id, student_id, issue_date))
cursor.execute("UPDATE Books SET Copies = Copies
- 1 WHERE BookID = ?", (book_id,))
conn.commit()
messagebox.showinfo("Success", "Book issued
successfully!")
else:
messagebox.showerror("Error", "Book not
available!")
conn.close()
# Return Book
def return_book(issue_id, return_date):
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
cursor.execute("SELECT BookID FROM IssuedBooks WHERE
IssueID = ?", (issue_id,))
issued = cursor.fetchone()
if issued:
cursor.execute("DELETE FROM IssuedBooks WHERE
IssueID = ?", (issue_id,))
cursor.execute("UPDATE Books SET Copies = Copies
+ 1 WHERE BookID = ?", (issued[0],))
conn.commit()
messagebox.showinfo("Success", "Book returned
successfully!")
else:
messagebox.showerror("Error", "Invalid Issue
ID!")
conn.close()
# GUI Setup
def main_gui():
root = Tk()
root.title("Library Management System")
# Frames
frame_top = Frame(root)
frame_top.pack(pady=10)
frame_bottom = Frame(root)
frame_bottom.pack(pady=10)
# Labels and Buttons
Label(frame_top, text="Library Management System",
font=("Arial", 24)).pack()
Button(frame_bottom, text="Add Book", command=lambda:
open_add_book()).grid(row=0, column=0, padx=20)
Button(frame_bottom, text="View Books",
command=lambda: open_view_books()).grid(row=0, column=1,
padx=20)
Button(frame_bottom, text="Issue Book",
command=lambda: open_issue_book()).grid(row=1, column=0,
padx=20)
Button(frame_bottom, text="Return Book",
command=lambda: open_return_book()).grid(row=1, column=1,
padx=20)
root.mainloop()
# Add Book GUI
def open_add_book():
def add():
title = entry_title.get()
author = entry_author.get()
copies = entry_copies.get()
if title and author and copies.isdigit():
add_book(title, author, int(copies))
window.destroy()
else:
messagebox.showerror("Error", "Invalid
input!")
window = Toplevel()
window.title("Add Book")
Label(window, text="Title:").grid(row=0, column=0,
padx=10, pady=10)
entry_title = Entry(window)
entry_title.grid(row=0, column=1, padx=10, pady=10)
Label(window, text="Author:").grid(row=1, column=0,
padx=10, pady=10)
entry_author = Entry(window)
entry_author.grid(row=1, column=1, padx=10, pady=10)
Label(window, text="Copies:").grid(row=2, column=0,
padx=10, pady=10)
entry_copies = Entry(window)
entry_copies.grid(row=2, column=1, padx=10, pady=10)
Button(window, text="Add", command=add).grid(row=3,
column=0, columnspan=2, pady=10)
# View Books GUI
def open_view_books():
books = view_books()
window = Toplevel()
window.title("View Books")
for idx, book in enumerate(books):
Label(window, text=f"{book}").grid(row=idx,
column=0, padx=10, pady=5)
# Issue Book GUI
def open_issue_book():
def issue():
book_id = entry_book_id.get()
student_id = entry_student_id.get()
issue_date = entry_issue_date.get()
if book_id.isdigit() and student_id.isdigit() and
issue_date:
issue_book(int(book_id), int(student_id),
issue_date)
window.destroy()
else:
messagebox.showerror("Error", "Invalid
input!")
window = Toplevel()
window.title("Issue Book")
Label(window, text="Book ID:").grid(row=0, column=0,
padx=10, pady=10)
entry_book_id = Entry(window)
entry_book_id.grid(row=0, column=1, padx=10, pady=10)
Label(window, text="Student ID:").grid(row=1,
column=0, padx=10, pady=10)
entry_student_id = Entry(window)
entry_student_id.grid(row=1, column=1, padx=10,
pady=10)
Label(window, text="Issue Date (YYYY-MM-
DD):").grid(row=2, column=0, padx=10, pady=10)
entry_issue_date = Entry(window)
entry_issue_date.grid(row=2, column=1, padx=10,
pady=10)
Button(window, text="Issue",
command=issue).grid(row=3, column=0, columnspan=2,
pady=10)
# Return Book GUI
def open_return_book():
def return_bk():
issue_id = entry_issue_id.get()
return_date = entry_return_date.get()
if issue_id.isdigit() and return_date:
return_book(int(issue_id), return_date)
window.destroy()
else:
messagebox.showerror("Error", "Invalid
input!")
window = Toplevel()
window.title("Return Book")
Label(window, text="Issue ID:").grid(row=0, column=0,
padx=10, pady=10)
entry_issue_id = Entry(window)
entry_issue_id.grid(row=0, column=1, padx=10,
pady=10)
Label(window, text="Return Date (YYYY-MM-
DD):").grid(row=1, column=0, padx=10, pady=10)
entry_return_date = Entry(window)
entry_return_date.grid(row=1, column=1, padx=10,
pady=10)
Button(window, text="Return",
command=return_bk).grid(row=2, column=0, columnspan=2,
pady=10)
# Main Execution
if _name_ == "_main_":
setup_database()
main_gui()
Output of the Program
Bibliography
1.GeeksforGeeks Python Resources
GeeksforGeeks. (n.d.). Python Programming Tutorials and
Resources. Retrieved from
https://www.geeksforgeeks.org/python-programming-
language/
2.Python Crash Course
Matthes, E. (2019). Python Crash Course: A Hands-On,
Project-Based Introduction to Programming (2nd ed.). No
Starch Press.
3.Real Python Tutorials
Real Python. (n.d.). Python Tutorials and Projects.
Retrieved from https://realpython.com/