Challenge

Project 1 - English Dictionary App & Library Book Management System

import tkinter as tk

from tkinter import messagebox

import pickle

def load_words():

try:

with open('words.txt', 'rb') as file:

words = pickle.load(file)

except (FileNotFoundError, EOFError):

words = {}

return words

def save_words(words):

with open('words.txt', 'wb') as file:

pickle.dump(words, file)

def add_word():

word = word_entry.get()

meaning = meaning_entry.get()

if word and meaning:

words[word] = meaning

save_words(words)

messagebox.showinfo("Success", f"Word '{word}' added successfully!")

else:

messagebox.showerror("Error", "Both word and meaning must be provided.")

reset_input_fields()

# Function to find the meaning of a word

def find_meaning():

word = word_entry.get()

if word in words:

meaning_label.config(text=f"Meaning: {words[word]}")

else:

meaning_label.config(text="Meaning: Word not found.")

reset_input_fields()

# Function to update the meaning of an existing word

def update_word():

word = word_entry.get()

if word in words:

new_meaning = meaning_entry.get()

words[word] = new_meaning

save_words(words)

messagebox.showinfo("Success", f"Word '{word}' updated successfully!")

else:

messagebox.showerror("Error", "Word not found.")

reset_input_fields()

# Reset input fields

def reset_input_fields():

word_entry.delete(0, tk.END)

meaning_entry.delete(0, tk.END)

def exit_app():

root.quit()

words = load_words()

root = tk.Tk()

root.title("English Dictionary App")

frame = tk.Frame(root)

frame.pack(pady=20)

add_button = tk.Button(frame, text="Add a new word", width=20, command=lambda: show_add_word_window())

add_button.grid(row=0, column=0, padx=10, pady=5)

find_button = tk.Button(frame, text="Find the meaning", width=20, command=lambda: show_find_word_window())

find_button.grid(row=1, column=0, padx=10, pady=5)

update_button = tk.Button(frame, text="Update a word", width=20, command=lambda: show_update_word_window())

update_button.grid(row=2, column=0, padx=10, pady=5)

exit_button = tk.Button(frame, text="Exit", width=20, command=exit_app)

exit_button.grid(row=3, column=0, padx=10, pady=5)

def show_add_word_window():

add_window = tk.Toplevel(root)

add_window.title("Add a new word")

tk.Label(add_window, text="Enter Word:").pack(pady=5)

word_entry = tk.Entry(add_window, width=30)

word_entry.pack(pady=5)

tk.Label(add_window, text="Enter Meaning:").pack(pady=5)

meaning_entry = tk.Entry(add_window, width=30)

meaning_entry.pack(pady=5)

add_button = tk.Button(add_window, text="Add Word", width=20, command=add_word)

add_button.pack(pady=20)

def show_find_word_window():

find_window = tk.Toplevel(root)

find_window.title("Find the meaning")

tk.Label(find_window, text="Enter Word:").pack(pady=5)

word_entry = tk.Entry(find_window, width=30)

word_entry.pack(pady=5)

find_button = tk.Button(find_window, text="Find Meaning", width=20, command=find_meaning)

find_button.pack(pady=20)

meaning_label = tk.Label(find_window, text="Meaning: ", width=30)

meaning_label.pack(pady=5)

def show_update_word_window():

update_window = tk.Toplevel(root)

update_window.title("Update a word")

tk.Label(update_window, text="Enter Word to Update:").pack(pady=5)

word_entry = tk.Entry(update_window, width=30)

word_entry.pack(pady=5)

tk.Label(update_window, text="Enter New Meaning:").pack(pady=5)

meaning_entry = tk.Entry(update_window, width=30)

meaning_entry.pack(pady=5)

update_button = tk.Button(update_window, text="Update Word", width=20, command=update_word)

update_button.pack(pady=20)

root.mainloop()

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.