বুক ম্যানেজমেন্ট সিস্টেম

প্র্যাকটিস প্রোজেক্টস - পাইথন ৩ (Python 3) - Computer Programming

231

বুক ম্যানেজমেন্ট সিস্টেম একটি অ্যাপ্লিকেশন যা বিভিন্ন বইয়ের তথ্য সংরক্ষণ, প্রদর্শন, সম্পাদনা এবং মুছে ফেলার জন্য ব্যবহৃত হয়। Python Tkinter এবং SQLite ব্যবহার করে একটি সহজ বুক ম্যানেজমেন্ট সিস্টেম তৈরি করা সম্ভব।


প্রজেক্ট: বুক ম্যানেজমেন্ট সিস্টেম

ফিচারস

  1. বই যোগ করা: নতুন বইয়ের তথ্য সংরক্ষণ করা।
  2. বই খোঁজা: বইয়ের নাম বা লেখকের ভিত্তিতে বই খোঁজা।
  3. বই সম্পাদনা: বিদ্যমান বইয়ের তথ্য আপডেট করা।
  4. বই মুছে ফেলা: নির্দিষ্ট বই ডাটাবেস থেকে মুছে ফেলা।
  5. বইয়ের তালিকা দেখানো: ডাটাবেসে থাকা সমস্ত বইয়ের তালিকা দেখানো।

প্রয়োজনীয় লাইব্রেরি

  • tkinter: GUI তৈরি করতে।
  • sqlite3: ডাটাবেস পরিচালনা করতে।

Python-এর SQLite এবং Tkinter লাইব্রেরি বিল্ট-ইন থাকে, তাই আলাদাভাবে ইনস্টলেশনের প্রয়োজন নেই।


Step 1: Tkinter এবং SQLite ইম্পোর্ট করা

import tkinter as tk
from tkinter import messagebox
import sqlite3

Step 2: SQLite ডাটাবেস তৈরি করা

SQLite ডাটাবেসে একটি টেবিল তৈরি করা হবে, যেখানে প্রতিটি বইয়ের নাম, লেখক, প্রকাশকের নাম এবং বছর সংরক্ষণ করা হবে।

# ডাটাবেস তৈরি এবং টেবিল সেটআপ
conn = sqlite3.connect("books.db")
cursor = conn.cursor()
cursor.execute("""
    CREATE TABLE IF NOT EXISTS books (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        title TEXT NOT NULL,
        author TEXT NOT NULL,
        publisher TEXT,
        year INTEGER
    )
""")
conn.commit()

Step 3: Tkinter GUI সেটআপ এবং এন্ট্রি ফিল্ড তৈরি

Tkinter GUI তৈরি করে ব্যবহারকারীর বইয়ের নাম, লেখক, প্রকাশক এবং বছরের তথ্য ইনপুট দেয়ার ব্যবস্থা করা হবে।

# মেইন Tkinter উইন্ডো তৈরি
root = tk.Tk()
root.title("Book Management System")
root.geometry("600x400")

# বইয়ের তথ্যের জন্য এন্ট্রি ফিল্ড
tk.Label(root, text="Title:").grid(row=0, column=0, padx=10, pady=5)
title_entry = tk.Entry(root, width=40)
title_entry.grid(row=0, column=1, padx=10, pady=5)

tk.Label(root, text="Author:").grid(row=1, column=0, padx=10, pady=5)
author_entry = tk.Entry(root, width=40)
author_entry.grid(row=1, column=1, padx=10, pady=5)

tk.Label(root, text="Publisher:").grid(row=2, column=0, padx=10, pady=5)
publisher_entry = tk.Entry(root, width=40)
publisher_entry.grid(row=2, column=1, padx=10, pady=5)

tk.Label(root, text="Year:").grid(row=3, column=0, padx=10, pady=5)
year_entry = tk.Entry(root, width=40)
year_entry.grid(row=3, column=1, padx=10, pady=5)

Step 4: বই যোগ করার ফাংশন

এই ফাংশনটি ব্যবহারকারীর ইনপুট তথ্য নিয়ে ডাটাবেসে সংরক্ষণ করবে।

def add_book():
    title = title_entry.get()
    author = author_entry.get()
    publisher = publisher_entry.get()
    year = year_entry.get()

    if title and author:
        cursor.execute("INSERT INTO books (title, author, publisher, year) VALUES (?, ?, ?, ?)", (title, author, publisher, year))
        conn.commit()
        messagebox.showinfo("Success", "Book added successfully!")
        display_books()
        clear_entries()
    else:
        messagebox.showwarning("Warning", "Please enter both title and author.")

Step 5: বইয়ের তথ্য ক্লিয়ার করার ফাংশন

def clear_entries():
    title_entry.delete(0, tk.END)
    author_entry.delete(0, tk.END)
    publisher_entry.delete(0, tk.END)
    year_entry.delete(0, tk.END)

Step 6: বইয়ের তালিকা দেখানোর ফাংশন

এই ফাংশনটি সমস্ত বই ডাটাবেস থেকে ফেচ করবে এবং GUI-তে দেখাবে।

def display_books():
    book_listbox.delete(0, tk.END)
    cursor.execute("SELECT title, author, publisher, year FROM books")
    for row in cursor.fetchall():
        book_listbox.insert(tk.END, f"{row[0]} by {row[1]} - {row[2]} ({row[3]})")

Step 7: বই মুছে ফেলার ফাংশন

def delete_book():
    selected_book = book_listbox.curselection()
    if selected_book:
        book_info = book_listbox.get(selected_book).split(" by ")
        title = book_info[0]
        cursor.execute("DELETE FROM books WHERE title = ?", (title,))
        conn.commit()
        display_books()
        messagebox.showinfo("Success", "Book deleted successfully!")
    else:
        messagebox.showwarning("Warning", "Please select a book to delete.")

Step 8: Tkinter GUI উইজেট এবং বাটন তৈরি

# বই যোগ করার বাটন
add_button = tk.Button(root, text="Add Book", command=add_book, width=15)
add_button.grid(row=4, column=0, padx=10, pady=10)

# বই মুছে ফেলার বাটন
delete_button = tk.Button(root, text="Delete Book", command=delete_book, width=15)
delete_button.grid(row=4, column=1, padx=10, pady=10)

# বইয়ের তালিকা দেখানোর জন্য লিস্টবক্স
book_listbox = tk.Listbox(root, width=70, height=10)
book_listbox.grid(row=5, column=0, columnspan=2, padx=10, pady=10)

display_books()  # প্রাথমিকভাবে ডাটাবেসের বই লোড করা

Step 9: Tkinter মেইন লুপ চালানো

root.mainloop()
conn.close()

পূর্ণ কোড একসাথে

import tkinter as tk
from tkinter import messagebox
import sqlite3

# ডাটাবেস তৈরি এবং টেবিল সেটআপ
conn = sqlite3.connect("books.db")
cursor = conn.cursor()
cursor.execute("""
    CREATE TABLE IF NOT EXISTS books (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        title TEXT NOT NULL,
        author TEXT NOT NULL,
        publisher TEXT,
        year INTEGER
    )
""")
conn.commit()

# মেইন Tkinter উইন্ডো তৈরি
root = tk.Tk()
root.title("Book Management System")
root.geometry("600x400")

# বইয়ের তথ্যের জন্য এন্ট্রি ফিল্ড
tk.Label(root, text="Title:").grid(row=0, column=0, padx=10, pady=5)
title_entry = tk.Entry(root, width=40)
title_entry.grid(row=0, column=1, padx=10, pady=5)

tk.Label(root, text="Author:").grid(row=1, column=0, padx=10, pady=5)
author_entry = tk.Entry(root, width=40)
author_entry.grid(row=1, column=1, padx=10, pady=5)

tk.Label(root, text="Publisher:").grid(row=2, column=0, padx=10, pady=5)
publisher_entry = tk.Entry(root, width=40)
publisher_entry.grid(row=2, column=1, padx=10, pady=5)

tk.Label(root, text="Year:").grid(row=3, column=0, padx=10, pady=5)
year_entry = tk.Entry(root, width=40)
year_entry.grid(row=3, column=1, padx=10, pady=5)

# বই যোগ করার ফাংশন
def add_book():
    title = title_entry.get()
    author = author_entry.get()
    publisher = publisher_entry.get()
    year = year_entry.get()

    if title and author:
        cursor.execute("INSERT INTO books (title, author, publisher, year) VALUES (?, ?, ?, ?)", (title, author, publisher, year))
        conn.commit()
        messagebox.showinfo("Success", "Book added successfully!")
        display_books()
        clear_entries()
    else:
        messagebox.showwarning("Warning", "Please enter both title and author.")

# এন্ট্রি ফিল্ড ক্লিয়ার করার ফাংশন
def clear_entries():
    title_entry.delete(0, tk.END)
    author_entry.delete(0, tk.END)
    publisher_entry.delete(0, tk.END)
    year_entry.delete(0, tk.END)

# বইয়ের তালিকা দেখানোর ফাংশন
def display_books():
    book_listbox.delete(0, tk.END)
    cursor.execute("SELECT title, author, publisher, year FROM books")
    for row in cursor.fetchall():
        book_listbox.insert(tk.END, f"{row[0]} by {row[1]} - {row[2]} ({row[3]})")

# বই মুছে ফেলার ফাংশন
def delete_book():
    selected_book = book_listbox.curselection()
    if selected_book:
        book_info = book_listbox.get(selected_book).split(" by ")
        title = book_info[0]
        cursor.execute("DELETE FROM books WHERE title = ?", (title,))
        conn.commit()
        display_books()
        messagebox.showinfo("Success", "Book deleted successfully!")
    else:
        messagebox.showwarning("Warning", "Please select a book to delete.")

# বই যোগ করার বাটন
add_button = tk.Button(root, text="Add Book", command=add_book, width=15)
add_button.grid(row=4, column=0, padx=10, pady=10)

# বই মুছে ফেলার বাটন
delete_button = tk.Button(root, text="Delete Book", command=delete_book, width=15)
delete_button.grid(row=4, column=1, padx=10, pady=10)

# বইয়ের তালিকা দেখানোর জন্য লিস্টবক্স
book_listbox = tk.Listbox(root, width=70, height=10)
book_listbox.grid(row=5, column=0, columnspan=2, padx=10, pady=10)

display_books()  # প্রাথমিকভাবে ডাটাবেসের বই লোড করা

root.mainloop()
conn.close()

কোড ব্যাখ্যা

SQLite Database: books.db নামে একটি SQLite ডাটাবেস তৈরি করা হয়েছে এবং books টেবিল তৈরি করা হয়েছে, যেখানে প্রতিটি বইয়ের শিরোনাম, লেখক, প্রকাশক এবং প্রকাশের বছর সংরক্ষণ করা হয়।

Tkinter GUI: Tkinter GUI তৈরি করা হয়েছে, যাতে ব্যবহারকারীরা বইয়ের শিরোনাম, লেখক, প্রকাশক এবং বছরের তথ্য ইনপুট দিতে পারেন।

add_book() Function: ইনপুট ফিল্ড থেকে ডেটা নিয়ে তা ডাটাবেসে সংরক্ষণ করে এবং GUI-তে প্রদর্শন করে।

display_books() Function: ডাটাবেস থেকে সমস্ত বইয়ের তথ্য সংগ্রহ করে GUI-তে প্রদর্শন করে।

delete_book() Function: নির্বাচিত বইটি ডাটাবেস থেকে মুছে ফেলে।


উপসংহার

এই বুক ম্যানেজমেন্ট সিস্টেম অ্যাপটি বিভিন্ন বই পরিচালনা করার জন্য একটি কার্যকরী টুল। SQLite ডাটাবেস ব্যবহার করে বইয়ের তথ্য সংরক্ষণ করা হয়েছে এবং Tkinter ব্যবহার করে GUI তৈরি করা হয়েছে।

Content added By
Promotion

Are you sure to start over?

Loading...