Project 1 - English Dictionary App & Library Book Management System
your files are all empty or either non server linked
import pickle
import os
import sqlite3
import tkinter as tk
from tkinter import messagebox
# 1A: English Dictionary App
WORDS_FILE = "words.txt"
def load_words():
if os.path.exists(WORDS_FILE):
with open(WORDS_FILE, "rb") as f:
return pickle.load(f)
return {}
def save_words(words):
with open(WORDS_FILE, "wb") as f:
pickle.dump(words, f)
def add_word():
word = input("Enter word: ")
meaning = input("Enter meaning: ")
words[word] = meaning
save_words(words)
print("Word added successfully!")
def find_meaning():
word = input("Enter word: ")
print("Meaning:", words.get(word, "Word not found!"))
def update_word():
word = input("Enter word to update: ")
if word in words:
meaning = input("Enter new meaning: ")
words[word] = meaning
save_words(words)
print("Word updated successfully!")
else:
print("Word not found!")
def main_menu():
while True:
print("\nMain Menu\n1. Add a new word\n2. Find the meaning\n3. Update a word\n4. Exit")
choice = input("Enter Choice: ")
if choice == "1":
add_word()
elif choice == "2":
find_meaning()
elif choice == "3":
update_word()
elif choice == "4":
print("Exiting... Goodbye!")
break
else:
print("Invalid choice! Try again.")
words = load_words()
main_menu()
# 1B: Library Book Management System
class LibraryApp:
def __init__(self, root):
self.root = root
self.root.title("Library Management System")
self.conn = sqlite3.connect("books.db")
self.cursor = self.conn.cursor()
self.create_table()
tk.Label(root, text="Title").grid(row=0, column=0)
tk.Label(root, text="Author").grid(row=1, column=0)
tk.Label(root, text="Year").grid(row=2, column=0)
tk.Label(root, text="ISBN").grid(row=3, column=0)
self.title_entry = tk.Entry(root)
self.title_entry.grid(row=0, column=1)
self.author_entry = tk.Entry(root)
self.author_entry.grid(row=1, column=1)
self.year_entry = tk.Entry(root)
self.year_entry.grid(row=2, column=1)
self.isbn_entry = tk.Entry(root)
self.isbn_entry.grid(row=3, column=1)
tk.Button(root, text="Add Book", command=self.add_book).grid(row=4, column=0)
tk.Button(root, text="View Books", command=self.view_books).grid(row=4, column=1)
tk.Button(root, text="Search", command=self.search_books).grid(row=5, column=0)
tk.Button(root, text="Delete", command=self.delete_book).grid(row=5, column=1)
self.listbox = tk.Listbox(root, height=8, width=40)
self.listbox.grid(row=6, column=0, columnspan=2)
def create_table(self):
self.cursor.execute('''CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY,
title TEXT,
author TEXT,
year INTEGER,
isbn TEXT)''')
self.conn.commit()
def add_book(self):
self.cursor.execute("INSERT INTO books (title, author, year, isbn) VALUES (?, ?, ?, ?)",
(self.title_entry.get(), self.author_entry.get(), self.year_entry.get(), self.isbn_entry.get()))
self.conn.commit()
self.view_books()
def view_books(self):
self.cursor.execute("SELECT * FROM books")
books = self.cursor.fetchall()
self.listbox.delete(0, tk.END)
for book in books:
self.listbox.insert(tk.END, book)
def search_books(self):
self.cursor.execute("SELECT * FROM books WHERE title=? OR author=? OR year=? OR isbn=?",
(self.title_entry.get(), self.author_entry.get(), self.year_entry.get(), self.isbn_entry.get()))
books = self.cursor.fetchall()
self.listbox.delete(0, tk.END)
for book in books:
self.listbox.insert(tk.END, book)
def delete_book(self):
selected = self.listbox.curselection()
if selected:
book_id = self.listbox.get(selected[0])[0]
self.cursor.execute("DELETE FROM books WHERE id=?", (book_id,))
self.conn.commit()
self.view_books()
else:
messagebox.showerror("Error", "Please select a book to delete")
if __name__ == "__main__":
root = tk.Tk()
app = LibraryApp(root)
root.mainloop()