Data Science

Library Management System in Python GUI with Source Code

Published: 26th May, 2023

Narender Ravulakollu

Technical Content Writer at almaBetter

Build a Simple Library Management using Python GUI and CSV files. Access complete source code to implement your own Library Management system using Python

In today's digital age, libraries have gone through a drastic transformation. From manual cataloging of books to automated systems, libraries have come a long way. The introduction of Library Management Systems (LMS) has streamlined the process of managing books, journals, and other resources in a library. These systems provide librarians with an efficient and convenient way to manage resources, maintain records, and track circulation.

Python, a popular programming language, is widely used in developing library management systems. With the availability of Python GUI libraries, it has become easier to build user-friendly interfaces for LMS applications. In this article, we will discuss the use of Python GUI libraries in creating a simple Library Management System project using CSV file storage. We will also provide a GitHub link to the project for further reference. Let's dive in and explore the world of Python GUI library and LMS.


In order to develop a library management system using Python GUI, there are certain requirements that need to be met. These include:

Python: Python is the primary language that will be used to develop the GUI and manage the system. Make sure that Python is installed on the computer.

GUI library: A GUI library is needed in order to create the graphical user interface for the system. There are several GUI libraries available for Python, including Tkinter, PyQt, wxPython, and PyGTK.

IDE: An integrated development environment (IDE) is recommended to facilitate coding and debugging. Some popular IDEs for Python include PyCharm, Visual Studio Code, and Spyder.

CSV file: The library management system will store and manage data using a CSV file. It is important to have a basic understanding of how to read from and write to CSV files using Python.

Functional requirements: The specific requirements of the library management system should be defined beforehand. This includes features such as adding new books, deleting books, searching for books, and updating book information. It is also important to consider how users will interact with the system and what actions they are allowed to perform.

By meeting these requirements, a functional library management system can be created using Python GUI.

Required Modules

To develop a library management system using Python GUI, we will require the following modules:

Tkinter: It is the standard Python GUI module and comes bundled with most Python installations. It provides a set of tools to create graphical user interfaces easily.

Pandas: It is a fast, powerful, and easy-to-use open-source data analysis and manipulation tool. It will be used to read, write, and manipulate data in CSV format.

CSV: It is a built-in Python module used to handle CSV (Comma Separated Values) files. It will be used to read and write data in CSV format.

Datetime: It is a built-in Python module that provides classes for working with dates and times. It will be used to store and manipulate dates in our library management system.

Random: It is a built-in Python module used to generate random numbers. It will be used to generate unique IDs for books and members in our library management system.

OS: It is a built-in Python module used to interact with the operating system. It will be used to check if a file exists, create a directory, and perform other file operations.

We will import these modules in our Python script to use their functionalities in our library management system.

Code Implementation

To implement a Library Management System using Python GUI, we can use the Tkinter module which is a standard GUI library for Python. In this project, we will be using a CSV file to store the details of books in the library.

Firstly, we need to import the required modules such as Tkinter, csv, and os.

import tkinter as tk
import csv
import os

Next, we can create a GUI window using the Tkinter module. Here, we can define the dimensions of the window, title of the window, and other properties.

window = tk.Tk()
window.title("Library Management System")

After creating the GUI window, we can add labels, buttons, and text boxes to the window. We can use the grid layout manager to organize the elements in the window.

# Labels
title_label = tk.Label(window, text="Library Management System", font=("Arial", 18))
title_label.grid(row=0, column=1, padx=10, pady=10)

book_label = tk.Label(window, text="Book Title")
book_label.grid(row=1, column=0, padx=10, pady=10)

author_label = tk.Label(window, text="Author")
author_label.grid(row=2, column=0, padx=10, pady=10)

isbn_label = tk.Label(window, text="ISBN")
isbn_label.grid(row=3, column=0, padx=10, pady=10)

# Text Boxes
book_textbox = tk.Entry(window)
book_textbox.grid(row=1, column=1, padx=10, pady=10)

author_textbox = tk.Entry(window)
author_textbox.grid(row=2, column=1, padx=10, pady=10)

isbn_textbox = tk.Entry(window)
isbn_textbox.grid(row=3, column=1, padx=10, pady=10)

# Buttons
add_button = tk.Button(window, text="Add Book"command=add_book)
add_button.grid(row=4, column=0, padx=10, pady=10)

view_button = tk.Button(window, text="View Books"command=view_books)
view_button.grid(row=4, column=1, padx=10, pady=10)

clear_button = tk.Button(window, text="Clear"command=clear_textboxes)
clear_button.grid(row=4, column=2, padx=10, pady=10)

In the above code, we have created labels for Book Title, Author, and ISBN. We have also created text boxes for the user to enter the details of the book. The add_button adds the details of the book to the CSV file, the view_button displays the list of books in the CSV file, and the clear_button clears the text boxes.

Now, we can define the functions that will be called when the buttons are clicked.

def add_book():
    book_title = book_textbox.get()
    author = author_textbox.get()
    isbn = isbn_textbox.get()
    with open("books.csv""a", newline="") as file:
        writer = csv.writer(file)
        writer.writerow([book_title, author, isbn])

def view_books():
    if os.path.exists("books.csv"):
        with open("books.csv""r") as file:
            reader = csv.reader(file)
            for row in reader:
        print("The CSV file does not exist.")

def clear_textboxes():
    book_textbox.delete(0, tk.END)
    author_textbox.delete(0, tk.END)
    isbn_textbox.delete(0, tk.END)

Source Code:

Here's the source code for creating a simple library management system project in Python using CSV file:

import csv
from tkinter import *
from tkinter import messagebox

# Function to add a book to the library
def add_book():
    # Get the values from the entry boxes
    book_id = book_id_entry.get()
    book_title = book_title_entry.get()
    book_author = book_author_entry.get()
    # Check if any field is empty
    if book_id == "" or book_title == "" or book_author == "":
        messagebox.showerror("Error""Please fill all the fields!")
        # Open the CSV file in append mode
        with open("library.csv""a") as file:
            writer = csv.writer(file)
            # Write the values to the file
            writer.writerow([book_id, book_title, book_author])
        # Show a success message
        messagebox.showinfo("Success""Book added successfully!")
        # Clear the entry boxes
        book_id_entry.delete(0, END)
        book_title_entry.delete(0, END)
        book_author_entry.delete(0, END)

# Function to search for a book
def search_book():
    # Get the value to search from the entry box
    search_value = search_entry.get()
    # Open the CSV file in read mode
    with open("library.csv""r") as file:
        reader = csv.reader(file)
        # Loop through the rows in the file
        for row in reader:
            # If the search value matches any of the fields
            if search_value in row:
                # Show the book details in a message box
                messagebox.showinfo("Book Details", f"Book ID: {row[0]}\nTitle: {row[1]}\nAuthor: {row[2]}")
                # Clear the search entry box
                search_entry.delete(0, END)
        # If no match was found, show an error message
        messagebox.showerror("Error""Book not found!")
        # Clear the search entry box
        search_entry.delete(0, END)

# Create the GUI
root = Tk()
root.title("Library Management System")

# Create the labels and entry boxes
Label(root, text="Book ID:").grid(row=0, column=0)
book_id_entry = Entry(root)
book_id_entry.grid(row=0, column=1)

Label(root, text="Title:").grid(row=1, column=0)
book_title_entry = Entry(root)
book_title_entry.grid(row=1, column=1)

Label(root, text="Author:").grid(row=2, column=0)
book_author_entry = Entry(root)
book_author_entry.grid(row=2, column=1)

Label(root, text="Search:").grid(row=3, column=0)
search_entry = Entry(root)
search_entry.grid(row=3, column=1)

# Create the buttons
add_button = Button(root, text="Add Book"command=add_book)
add_button.grid(row=4, column=0)

search_button = Button(root, text="Search Book"command=search_book)
search_button.grid(row=4, column=1)



Screenshot 2023-05-02 at 12.43.51 PM.png

Some other information about Project:

Here are some additional information about the Library Management System project:

  • This project can be expanded further by adding more features such as user authentication, book recommendations, and fine calculation.
  • This project uses a CSV file to store and retrieve information. However, it can also be integrated with a database like MySQL or SQLite for better scalability.
  • The graphical user interface (GUI) of this project is built using the Tkinter module in Python. Tkinter is a standard GUI library for Python and comes pre-installed with most Python installations.
  • This project is designed to be beginner-friendly and can be used as a learning resource for those who are new to Python and GUI programming.
  • The project follows the Model-View-Controller (MVC) architectural pattern. The Model represents the data and business logic, the View represents the user interface, and the Controller acts as an intermediary between the Model and View.
  • The project includes detailed documentation and comments throughout the code to help users understand how the project works and how it can be modified to suit their needs.

Learn more with our new guides on "How to Create an Onscreen GUI Piano in Python" and "How to Create CSV File in Python"


The Library Management System project implemented using Python GUI provides a user-friendly interface for managing library tasks efficiently. With the use of the Tkinter GUI library and CSV module, this project provides an easy way to store and manage book data, borrow/return books, and generate reports.

This project also serves as an excellent starting point for developers who want to learn more about building GUI applications with Python. By studying this project's source code and experimenting with its features, developers can gain valuable experience in GUI programming, data handling, and project development.

Overall, the Library Management System project in Python using the GUI approach is an excellent example of how to leverage Python's powerful features to create robust and user-friendly applications.

Related Articles

Top Tutorials

Made with heartin Bengaluru, India
  • Official Address
  • 4th floor, 133/2, Janardhan Towers, Residency Road, Bengaluru, Karnataka, 560025
  • Communication Address
  • 4th floor, 315 Work Avenue, Siddhivinayak Tower, 152, 1st Cross Rd., 1st Block, Koramangala, Bengaluru, Karnataka, 560034
  • Follow Us
  • facebookinstagramlinkedintwitteryoutubetelegram

© 2024 AlmaBetter