From 3629545bce090f14ac891f386c90485b4dc0abad Mon Sep 17 00:00:00 2001 From: IAMSMR007 Date: Thu, 27 Mar 2025 21:06:08 +0530 Subject: [PATCH] Flashcard App Added --- Flashcard App/data/translation.txt | 435 +++++++++++++++++++++++++++++ Flashcard App/main.py | 198 +++++++++++++ 2 files changed, 633 insertions(+) create mode 100644 Flashcard App/data/translation.txt create mode 100644 Flashcard App/main.py diff --git a/Flashcard App/data/translation.txt b/Flashcard App/data/translation.txt new file mode 100644 index 00000000000..bee1e83d06a --- /dev/null +++ b/Flashcard App/data/translation.txt @@ -0,0 +1,435 @@ +English,Hindi +the,द +be,होना +to,को +of,का +and,और +a,एक +in,में +that,कि +have,रखना +it,यह +for,के लिए +not,नहीं +on,पर +with,के साथ +he,वह +as,जैसे +you,तुम +do,करना +at,पर +this,यह +but,लेकिन +his,उसका +from,से +they,वे +we,हम +say,कहना +her,उसकी +she,वह +or,या +an,एक +will,होगा +my,मेरा +one,एक +would,होगा +there,वहां +what,क्या +up,ऊपर +out,बाहर +if,अगर +about,लगभग +who,जो +get,पाना +which,जो +go,जाना +me,मुझे +when,जब +can,सकना +like,जैसा +time,समय +no,नहीं +just,बस +him,उसे +know,जानना +take,लेना +people,लोग +into,में +year,साल +your,आपका +good,अच्छा +some,कुछ +could,सकता +them,उन्हें +see,देखना +other,अन्य +than,से +then,फिर +now,अब +look,देखना +only,केवल +come,आना +its,इसका +over,ऊपर +also,भी +back,पीछे +after,के बाद +use,उपयोग +two,दो +how,कैसे +our,हमारा +work,काम +first,पहला +well,अच्छा +way,तरीका +even,भी +new,नया +any,कोई +give,देना +day,दिन +most,अधिकांश +us,हम +is,है +are,हैं +has,है +were,थे +had,था +been,होना +may,हो सकता है +many,कई +must,होना चाहिए +such,ऐसा +more,अधिक +should,चाहिए +little,थोड़ा +much,बहुत +how,कैसे +why,क्यों +where,कहाँ +because,क्योंकि +through,के माध्यम से +before,पहले +after,बाद +between,के बीच +under,के नीचे +again,फिर +further,आगे +once,एक बार +here,यहाँ +there,वहाँ +when,जब +where,कहाँ +why,क्यों +how,कैसे +all,सभी +any,कोई +both,दोनों +each,प्रत्येक +few,कुछ +more,अधिक +most,अधिकांश +other,अन्य +some,कुछ +such,ऐसा +no,नहीं +nor,न ही +not,नहीं +only,केवल +same,समान +so,तो +than,से +too,बहुत +very,बहुत +a,एक +an,एक +the,द +and,और +but,लेकिन +if,अगर +or,या +because,क्योंकि +as,जैसे +until,जब तक +while,जबकि +of,का +at,पर +by,द्वारा +for,के लिए +with,के साथ +about,लगभग +against,के खिलाف +between,के बीच +into,में +through,के माध्यम से +during,के दौरान +before,पहले +after,बाद +above,ऊपर +below,नीचे +to,को +from,से +up,ऊपर +down,नीचे +in,में +out,बाहर +on,पर +off,बंद +over,ऊपर +under,के नीचे +again,फिर +further,आगे +then,तब +once,एक बार +here,यहाँ +there,वहाँ +when,जब +where,कहाँ +why,क्यों +how,कैसे +all,सभी +any,कोई +both,दोनों +each,प्रत्येक +few,कुछ +more,अधिक +most,अधिकांश +other,अन्य +some,कुछ +such,ऐसा +no,नहीं +nor,न ही +not,नहीं +only,केवल +same,समान +so,तो +than,से +too,बहुत +very,बहुत +can,सकना +will,होगा +just,बस +should,चाहिए +now,अब +want,चाहना +like,जैसा +better,बेहतर +best,सबसे अच्छा +would,होगा +could,सकता +might,हो सकता है +must,होना चाहिए +shall,होना चाहिए +always,हमेशा +often,अक्सर +sometimes,कभी-कभी +never,कभी नहीं +still,अभी भी +only,केवल +just,बस +really,वास्तव में +actually,वास्तव में +perhaps,शायद +mainly,मुख्य रूप से +simply,बस +clearly,स्पष्ट रूप से +probably,संभवतः +finally,अंत में +potentially,संभावित रूप से +actually,वास-तव में +certainly,निश्चित रूप से +obviously,स्पष्ट रूप से +specifically,विशेष रूप से +basically,मूल रूप से +virtually,लगभग +absolutely,बिल्कुल +completely,पूरी तरह से +totally,पूरी तरह से +entirely,पूरी तरह से +generally,सामान्यतः +normally,सामान्य रूप से +regularly,नियमित रूप से +traditionally,पारंपरिक रूप से +usually,आमतौर पर +possible,संभव +impossible,असंभव +necessary,आवश्यक +important,महत्वपूर्ण +essential,आवश्यक +significant,महत्वपूर्ण +crucial,महत्वपूर्ण +vital,महत्वपूर्ण +potential,संभावित +specific,विशिष्ट +particular,विशेष +unique,अनूठा +different,अलग +similar,समान +various,विभिन्न +alternative,वैकल्पिक +additional,अतिरिक्त +extra,अतिरिक्त +major,प्रमुख +minor,छोटा +primary,प्राथमिक +secondary,द्वितीयक +normal,सामान्य +unusual,असामान्य +common,सामान्य +rare,दुर्लभ +strange,अजीब +odd,विचित्र +perfect,पूर्ण +complete,पूर्ण +entire,पूरा +whole,पूरा +half,आधा +part,भाग +section,अनुभाग +piece,टुकड़ा +bit,थोड़ा +aspect,पहलू +element,तत्व +feature,विशेषता +quality,गुण +property,संपत्ति +characteristic,विशेषता +nature,प्रकृति +type,प्रकार +kind,तरह +sort,तरह +form,रूप +structure,संरचना +style,शैली +pattern,पैटर्न +design,डिजाइन +system,प्रणाली +method,विधि +process,प्रक्रिया +approach,दृष्टिकोण +technique,तकनीक +way,तरीका +manner,तरीका +mode,मोड +means,माध्यम +result,परिणाम +outcome,परिणाम +consequence,परिणाम +effect,प्रभाव +impact,प्रभाव +significance,महत्व +importance,महत्व +value,मूल्य +meaning,अर्थ +purpose,उद्देश्य +reason,कारण +cause,कारण +factor,कारक +source,स्रोत +origin,मूल +basis,आधार +context,संदर्भ +situation,स्थिति +condition,स्थिति +circumstance,परिस्थिति +state,राज्य +position,स्थिति +relation,संबंध +connection,संबंध +link,लिंक +association,संघ +interaction,अंतः क्रिया +influence,प्रभाव +role,भूमिका +function,कार्य +part,भाग +place,स्थान +space,जगह +position,स्थिति +area,क्षेत्र +region,क्षेत्र +zone,क्षेत्र +range,श्रेणी +site,स्थल +moment,क्षण +stage,चरण +phase,चरण +period,अवधि +time,समय +instance,उदाहरण +case,मामला +example,उदाहरण +sample,नमूना +experience,अनुभव +incident,घटना +event,घटना +occurrence,घटना +situation,स्थिति +circumstance,परिस्थिति +background,पृष्ठभूमि +context,संदर्भ +condition,स्थिति +environment,पर्यावरण +setting,सेटिंग +scene,दृश्य +scenario,परिदृश्य +story,कहानी +account,खाता +detail,विवरण +particular,विशेष +specific,विशिष्ट +aspect,पहलू +element,तत्व +feature,विशेषता +characteristic,विशेषता +quality,गुण +property,संपत्ति +nature,प्रकृति +type,प्रकार +kind,तरह +sort,तरह +form,रूप +shape,आकार +structure,संरचना +style,शैली +pattern,पैटर्न +design,डिजाइन +system,प्रणाली +method,विधि +process,प्रक्रिया +approach,दृष्टिकोण +technique,तकनीक +way,तरीका +manner,तरीका +mode,मोड +means,माध्यम +result,परिणाम +outcome,परिणाम +consequence,परिणाम +effect,प्रभाव +impact,प्रभाव +significance,महत्व +importance,महत्व +value,मूल्य +meaning,अर्थ +point,बिंदु +purpose,उद्देश्य +reason,कारण +cause,कारण +factor,कारक +source,स्रोत +origin,मूल +basis,आधार +context,संदर्भ +situation,स्थिति +condition,स्थिति +circumstance,परिस्थिति +state,राज्य +position,स्थिति +relation,संबंध +connection,संबंध +link,लिंक +association,संघ +interaction,अंतः क्रिया +influence,प्रभाव +role,भूमिका +function,कार्य diff --git a/Flashcard App/main.py b/Flashcard App/main.py new file mode 100644 index 00000000000..099b3693d5e --- /dev/null +++ b/Flashcard App/main.py @@ -0,0 +1,198 @@ +from tkinter import * +import pandas as pd +import random +import os + +# Constants +FRONT_COLOR = "#B1DDC6" # Green background for front +BACK_COLOR = "#F08080" # Red background for back +BUTTON_RED = "#FF5555" # Bright red for buttons +BUTTON_GREEN = "#4CAF50" # Green for tick and wrong buttons +FLIP_TIME_MS = 3000 # Time before card flips (3 seconds) +FONT_NAME = "Arial" +WINDOW_WIDTH = 400 # Further reduced window width +WINDOW_HEIGHT = 300 # Further reduced window height +PADDING = 20 # Reduced padding + +# ---------------------------- DATA SETUP ------------------------------- # +def load_data(): + """Load word data from CSV file""" + try: + # Try to load from word_to_learn.csv first + data_file = "data/word_to_learn.csv" + data = pd.read_csv(data_file) + + # If file exists but is empty or has only headers + if len(data) == 0: + raise pd.errors.EmptyDataError("Empty file") + + except (FileNotFoundError, pd.errors.EmptyDataError): + # If word_to_learn.csv doesn't exist or is empty, load from translation.txt + source_file = "data/translation.txt" + source_data = pd.read_csv(source_file) + + # Save all data to word_to_learn.csv + data_file = "data/word_to_learn.csv" + source_data.to_csv(data_file, index=False) + data = source_data + + return data.to_dict(orient='records'), data_file + +to_learn, data_file = load_data() +current_card = {} +flip_timer = None + +# ---------------------------- CARD FUNCTIONS ------------------------------- # +def next_card(): + """Display a new random English word from the word list""" + global current_card, flip_timer + + # Cancel previous timer if exists + if flip_timer: + window.after_cancel(flip_timer) + + # Check if we have words left to learn + if not to_learn: + show_completion_message() + return + + # Select a random word and display on card front + current_card = random.choice(to_learn) + canvas.config(bg=FRONT_COLOR) + canvas.itemconfig(card_title, text="English", fill="black") + canvas.itemconfig(card_word, text=current_card["English"], fill="black") + + # Set timer to flip card after delay + flip_timer = window.after(FLIP_TIME_MS, flip_card) + +def flip_card(): + """Flip the card to show the Hindi translation""" + canvas.config(bg=BACK_COLOR) + canvas.itemconfig(card_title, text="Hindi", fill="white") + canvas.itemconfig(card_word, text=current_card["Hindi"], fill="white") + +def remove_card(): + """Remove the current card from the deck when user knows it (✓ button)""" + global to_learn + + # Remove current card from the deck + to_learn.remove(current_card) + + # Save updated word list to word_to_learn.csv + pd.DataFrame(to_learn).to_csv(data_file, index=False) + + # Show next card + next_card() + +def skip_card(): + """Skip current card (❌ button) without removing it from the deck""" + # Just move to the next card without changing the deck + next_card() + +def show_completion_message(): + """Display completion message when all words are learned""" + canvas.config(bg=FRONT_COLOR) + canvas.itemconfig(card_title, text="Congratulations!", fill="black") + canvas.itemconfig(card_word, text="You've learned all the words!", fill="black") + + # Disable buttons when complete + wrong_button.config(state="disabled") + right_button.config(state="disabled") + +def reset_progress(): + """Reset progress by reloading all words from translation.txt""" + global to_learn, data_file + + # Reload original word list from translation.txt + source_file = "data/translation.txt" + source_data = pd.read_csv(source_file) + + # Save all data to word_to_learn.csv + data_file = "data/word_to_learn.csv" + source_data.to_csv(data_file, index=False) + + # Update current deck + to_learn = source_data.to_dict(orient='records') + + # Enable buttons + wrong_button.config(state="normal") + right_button.config(state="normal") + + # Show a new card + next_card() + +# ------------------------------- UI SETUP ------------------------------- # +window = Tk() +window.title("Flashy - English-Hindi Learning App") +window.config(background=FRONT_COLOR, padx=PADDING, pady=PADDING) + +# Canvas for the flashcard - no card images, just colored background +canvas = Canvas(width=WINDOW_WIDTH, height=WINDOW_HEIGHT, bg=FRONT_COLOR, highlightthickness=1, highlightbackground="gray") + +# Text elements on the card +card_title = canvas.create_text(WINDOW_WIDTH//2, WINDOW_HEIGHT//3, text="", font=(FONT_NAME, 24, "italic")) +card_word = canvas.create_text(WINDOW_WIDTH//2, WINDOW_HEIGHT//2, text="", font=(FONT_NAME, 36, "bold")) +canvas.grid(row=0, column=0, columnspan=2, padx=10, pady=10) + +# Buttons +wrong_button = Button( + text="❌", + font=(FONT_NAME, 16), + highlightthickness=0, + bg=BUTTON_GREEN, + fg="white", + activebackground="#3E8E41", # Darker green when clicked + activeforeground="white", + border=0, + command=skip_card +) +wrong_button.grid(row=1, column=0, pady=10) + +right_button = Button( + text="✓", + font=(FONT_NAME, 16), + highlightthickness=0, + bg=BUTTON_GREEN, + fg="white", + activebackground="#3E8E41", # Darker green when clicked + activeforeground="white", + border=0, + command=remove_card +) +right_button.grid(column=1, row=1, pady=10) + +# Bottom row buttons +button_frame = Frame(window, bg=FRONT_COLOR) +button_frame.grid(row=2, column=0, columnspan=2, pady=10) + +# Reset button +reset_button = Button( + button_frame, + text="Reset Progress", + highlightthickness=0, + bg=BUTTON_RED, + fg="white", + activebackground="#FF3333", + activeforeground="white", + command=reset_progress +) +reset_button.grid(row=0, column=0, padx=5) + +# Exit button +exit_button = Button( + button_frame, + text="Exit", + highlightthickness=0, + bg=BUTTON_RED, + fg="white", + activebackground="#FF3333", + activeforeground="white", + command=window.destroy +) +exit_button.grid(row=0, column=1, padx=5) + +# Initialize with the first card +next_card() + +window.mainloop() +