Computer Science Project
Computer Science Project
KhasraNo:50/3-50/7GotadPanjri,BesaNagpur-440037 CBSE
Submitted By
Class XII has taken keen interest and with utmost sincerity
Principal InternalExaminer/ProjectMentor
ExternalExaminer
ACKNOWLEDGEMENT
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 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.
Hardwares
1.DesktopComputer/Laptop
2.MobilePhone
Softwares
1.Python (LatestVersion)
2.MySQL
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.
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.
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.
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
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:
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.
Books Table:
3.IssuedBooks Table:
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.
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()
conn.commit()
conn.close()
# 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()
# Return Book
def return_book(issue_id, return_date):
conn = sqlite3.connect("library.db")
cursor = conn.cursor()
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)
root.mainloop()
window = Toplevel()
window.title("Add Book")
window = Toplevel()
window.title("View Books")
window = Toplevel()
window.title("Issue Book")
window = Toplevel()
window.title("Return Book")
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