LMS

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Introduction to Python

Python is like a versatile tool for programmers. It's popular because it's easy to use, has lots
of helpful features, and can be used for many different things. Whether you're just starting or
you're an experienced coder, Python might be a good fit for you. Before you start using
Python, let's talk about what makes it special and where it might have some challenges.

Python's Simplicity: Good for Everyone


One great thing about Python is that ist's easy to understand. Unlike some other coding
languages that look like puzzles, Python looks more like regular language. This makes it nice
for beginners because they can focus on solving problems instead of struggling with
complicated rules. Even people who have been coding for a while like Python because it's
clear and makes writing and fixing code quicker.
Beyond Beginner-Friendly: Can Do a Lot
Even though Python is good for beginners, it can do a lot more than just basic stuff. It has
many libraries and tools, so you can use it for different kinds of projects. You can build
websites, analyze data, automate tasks, and even work on things like artificial intelligence
and machine learning.
Advantages that Make Python Great:
Can Do Many Things: Python can be used for lots of different tasks, from making websites
to doing science stuff.
Helpful Community: Many programmers around the world use Python, and they're ready to
help and share what they know.
Free to Use: You don't need to pay to use Python, and anyone can learn it without any special
costs.
Easy to Test Ideas: Python lets you quickly try out and improve your ideas because it's easy
to write and understand.
Code is Easy to Read: Python code is clear and easy to understand, making it simple for
people to work together and update code later.
A Balanced View: Things to Watch Out For in Python
While Python is great, it's not perfect. Here are a couple of things to keep in mind:
Not the Fastest: Compared to some other languages, like C++, Python can be slower. But
many people think the trade-off is worth it for faster development.
Uses More Memory: Python programs might use more computer memory than others. You
can make it better by writing efficient code and choosing the right tools.
Not Top Choice for Mobile Apps: While Python is getting better for making mobile apps, it's
not the best choice for that
Hardware and Software Requirements

Minimum Software Requirements:

- Python Interpreter:
- Version: Python 3.x (Recommended)
- Backup System (Optional): Implement regular backups for data safety

Minimum Hardware Requirements:


Computer:
Any standard desktop or laptop computer.
Processor:
A basic processor, such as an Intel Core i3 or equivalent.
Memory (RAM):
2GB of RAM.
Storage:
A few megabytes of available storage space. The code and data are small.
Operating System:
The code is platform-independent and should work on various operating systems,
including Windows, macOS, and Linux.
Introduction To Library Management System

A library management system (LMS) is a software application or a set of related programs


that help in the efficient management of library resources. The primary purpose of an LMS is
to automate library tasks and facilitate easy access to information. Here are some common
uses of a library management system:

Graphical User Interface (GUI):


The code utilizes Tkinter, a standard GUI toolkit for Python, to create a user-friendly
interface.
Labels, Entry widgets, and Buttons are employed to design the layout for entering book
details, adding books, and displaying the list of books.

Adding Books:
Users can input book details such as Title, Author, and ISBN through the Entry widgets.
The "Add Book" button triggers the add_book method, which validates the input fields and
adds the book information to a CSV file (library.csv).
A csv.DictWriter is used to write data to the CSV file, and it ensures that headers are written
only if the file is empty.
Displaying Books:
The "Show Books" button opens a new window (books_window) to display the list of books.
The list of books is fetched from the CSV file using csv.DictReader.
Book information is presented in a Tkinter Listbox within the books_window.

Error Handling and Notifications:


The messagebox module from Tkinter is utilized for displaying informative messages and
warnings.
Users receive notifications about successful book additions or errors, such as empty input
fields.
Data Persistence:
Book information is stored in a CSV file (library.csv), providing a simple form of data
persistence.
The CSV file serves as a database for maintaining a record of added books.

Separation of Concerns:
The code follows a structured approach by defining a LibraryManagementSystem class,
encapsulating related functionalities within the class methods.
This promotes modularity and maintainability.

Main Program Structure:


The code structure includes a main block (if __name__ == "__main__":) to instantiate the
Tkinter root window and start the event loop.

Minimum Hardware and Software Requirements:


The code has minimal hardware and software requirements, making it accessible for a wide
range of systems.

Comments and Readability:


The code includes comments that provide explanations for different sections, enhancing code
readability and understanding.
Source Code

import csv
from tkinter import *
from tkinter import messagebox

class LibraryManagementSystem:
def __init__(self, root):
self.root = root
self.root.title("Library Management System")

self.title_label = Label(root, text="Library Management System", font=("Helvetica", 16,


"bold"))
self.title_label.grid(row=0, column=1, pady=10)

# Labels and Entry Widgets


self.title_entry = Entry(root, width=30)
self.title_label = Label(root, text="Title:")
self.title_label.grid(row=1, column=0, padx=10, pady=10)
self.title_entry.grid(row=1, column=1, padx=10, pady=10)

self.author_entry = Entry(root, width=30)


self.author_label = Label(root, text="Author:")
self.author_label.grid(row=2, column=0, padx=10, pady=10)
self.author_entry.grid(row=2, column=1, padx=10, pady=10)

self.isbn_entry = Entry(root, width=30)


self.isbn_label = Label(root, text="ISBN:")
self.isbn_label.grid(row=3, column=0, padx=10, pady=10)
self.isbn_entry.grid(row=3, column=1, padx=10, pady=10)
# Buttons
self.add_button = Button(root, text="Add Book", command=self.add_book)
self.add_button.grid(row=4, column=0, columnspan=2, pady=10)

self.show_books_button = Button(root, text="Show Books",


command=self.show_books)
self.show_books_button.grid(row=5, column=0, columnspan=2, pady=10)

def add_book(self):
title = self.title_entry.get()
author = self.author_entry.get()
isbn = self.isbn_entry.get()

if title and author and isbn:


with open('library.csv', 'a', newline='') as csvfile:
fieldnames = ['Title', 'Author', 'ISBN']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

# Check if the file is empty, write headers


if csvfile.tell() == 0:
writer.writeheader()

writer.writerow({'Title': title, 'Author': author, 'ISBN': isbn})

messagebox.showinfo("Success", "Book added successfully!")


else:
messagebox.showerror("Error", "Please fill in all fields.")

def show_books(self):
books_window = Toplevel(self.root)
books_window.title("List of Books")
# Create a listbox to display books
listbox = Listbox(books_window, width=50)
listbox.pack(pady=20)

try:
with open('library.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
listbox.insert(END, f"Title: {row['Title']}, Author: {row['Author']}, ISBN:
{row['ISBN']}")
except FileNotFoundError:
messagebox.showwarning("Warning", "Library file not found. Add books to create
the file.")

# Main Program
if __name__ == "__main__":
root = Tk()
app = LibraryManagementSystem(root)
root.mainloop()
Output
Bibliography

Computer Science with Python – Sumita Arora


YouTube - https://youtu.be/MFhxShGxHWc?si=kdHtAX_ DPNbLNXEy
YouTube - https://youtu.be/GDymNBT_o_g

You might also like