{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Spanish to English learning flash card app\n", "\n", "This is a simple app to help anyone learn Spanish. It is a simple flash card app that shows a Spanish word and the user has to guess the English translation. \n", "\n", "### Features\n", "\n", "- The app has a simple UI with a button to show the answer and a button to note down if the user got the answer right or wrong.\n", "- The app has a simple database that stores the words and their translations.\n", "- The correctly answered words are removed from the database and the incorrectly answered words are added back to the database.\n", "\n", "### How to use\n", "\n", "- The app is simple to use. Just run the app and click on the button to show the answer.\n", "- Then click on the button to note down if the user got the answer right or wrong.\n", "- The app will then show the next word and the process repeats.\n", "- Clink on spain logo or UK logo to see spanish and english meanings respectively.\n", "\n", "### How to install\n", "\n", "- The app is a simple python script that can be run on any system with python installed.\n", "- The app uses the `tkinter` module for the UI and the `pandas` module for the csv database.\n", "- The csv database is included in the repository and can be edited to add more words." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> Below is the snapshot of the app\n", "\n", "![App](app.png)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "68\n", "67\n", "66\n", "65\n", "64\n", "63\n", "62\n", "61\n", "60\n", "59\n", "58\n", "57\n", "56\n", "55\n", "54\n", "53\n", "52\n", "51\n", "50\n", "49\n", "48\n", "47\n", "46\n", "45\n" ] } ], "source": [ "from tkinter import *\n", "import pandas\n", "import random\n", "\n", "# Set the background color for the flashcards\n", "BACKGROUND_COLOR = \"#08cf96\"\n", "\n", "# Initialize the current flashcard and the list of flashcards to learn\n", "current_flashcard = {}\n", "flashcards_to_learn = {}\n", "\n", "# Load the flashcards from a CSV file\n", "flashcard_data = pandas.read_csv(\"data/words_to_learn.csv\")\n", "flashcards_to_learn = flashcard_data.to_dict(orient=\"records\")\n", "\n", "# Function to display the next flashcard\n", "def display_next_flashcard():\n", " global current_flashcard, flip_timer\n", " window.after_cancel(flip_timer)\n", " current_flashcard = random.choice(flashcards_to_learn)\n", " canvas.itemconfig(flashcard_title, text=\"Spanish\", fill=\"black\")\n", " canvas.itemconfig(flashcard_word, text=current_flashcard[\"Spanish\"], fill=\"black\")\n", " canvas.itemconfig(flashcard_background, image=flashcard_front_img)\n", " flip_timer = window.after(3000, func=flip_flashcard)\n", "\n", "# Function to flip the flashcard to the English side\n", "def flip_flashcard():\n", " canvas.itemconfig(flashcard_title, text=\"English\", fill=\"white\")\n", " canvas.itemconfig(flashcard_word, text=current_flashcard[\"English\"], fill=\"white\")\n", " canvas.itemconfig(flashcard_background, image=flashcard_back_img)\n", "\n", "# Function to flip the flashcard back to the Spanish side\n", "def reverse_flashcard():\n", " canvas.itemconfig(flashcard_title, text=\"Spanish\", fill=\"black\")\n", " canvas.itemconfig(flashcard_word, text=current_flashcard[\"Spanish\"], fill=\"black\")\n", " canvas.itemconfig(flashcard_background, image=flashcard_front_img)\n", "\n", "# Function to mark the current flashcard as known and remove it from the list of flashcards to learn\n", "def mark_flashcard_as_known():\n", " flashcards_to_learn.remove(current_flashcard)\n", " print(len(flashcards_to_learn))\n", " flashcard_data = pandas.DataFrame(flashcards_to_learn)\n", " flashcard_data.to_csv(\"data/words_to_learn.csv\", index=False)\n", " display_next_flashcard()\n", "\n", "# Create the main window\n", "window = Tk()\n", "window.title(\"My Flashcards\")\n", "window.config(padx=50, pady=50, bg=BACKGROUND_COLOR)\n", "\n", "# Set a timer to automatically flip the flashcard after 3 seconds\n", "flip_timer = window.after(3000, func=flip_flashcard)\n", "\n", "# Create the canvas to display the flashcards\n", "canvas = Canvas(width=800, height=526)\n", "flashcard_front_img = PhotoImage(file=\"images/card_front.png\")\n", "flashcard_back_img = PhotoImage(file=\"images/card_back.png\")\n", "flashcard_background = canvas.create_image(400, 263, image=flashcard_front_img)\n", "flashcard_title = canvas.create_text(400, 150, text=\"\", font=(\"Ariel\", 40, \"italic\"))\n", "flashcard_word = canvas.create_text(400, 263, text=\"\", font=(\"Ariel\", 60, \"bold\"))\n", "canvas.config(bg=BACKGROUND_COLOR, highlightthickness=0)\n", "canvas.grid(row=0, column=0, columnspan=2)\n", "\n", "# Create the buttons to control the flashcards\n", "wrong_image = PhotoImage(file=\"images/wrong.png\")\n", "unknown_flashcard_button = Button(image=wrong_image, highlightthickness=0, command=display_next_flashcard)\n", "unknown_flashcard_button.grid(row=1, column=0, padx=20, pady=20)\n", "\n", "right_image = PhotoImage(file=\"images/right.png\")\n", "known_flashcard_button = Button(image=right_image, highlightthickness=0, command=mark_flashcard_as_known)\n", "known_flashcard_button.grid(row=1, column=1)\n", "\n", "flip_image = PhotoImage(file=\"images/spanish.png\")\n", "flip_flashcard_button = Button(image=flip_image, highlightthickness=0, command=reverse_flashcard)\n", "flip_flashcard_button.grid(row=2, column=0)\n", "\n", "reverse_image = PhotoImage(file=\"images/english.png\")\n", "reverse_flashcard_button = Button(image=reverse_image, highlightthickness=0, command=flip_flashcard)\n", "reverse_flashcard_button.grid(row=2, column=1)\n", "\n", "# Start the application by displaying the first flashcard\n", "display_next_flashcard()\n", "\n", "# Start the main event loop for the application\n", "window.mainloop()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 2 }