Professional Documents
Culture Documents
LMS
LMS
LMS
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 Interpreter:
- Version: Python 3.x (Recommended)
- Backup System (Optional): Implement regular backups for data safety
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.
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.
import csv
from tkinter import *
from tkinter import messagebox
class LibraryManagementSystem:
def __init__(self, root):
self.root = root
self.root.title("Library Management System")
def add_book(self):
title = self.title_entry.get()
author = self.author_entry.get()
isbn = self.isbn_entry.get()
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