| 26 | |
| 27 | #finding correct match |
| 28 | def translate(word, file): |
| 29 | word = word.lower() |
| 30 | if word in file: |
| 31 | return file[word], None |
| 32 | elif word.title() in file: |
| 33 | return file[word.title()], None |
| 34 | elif word.upper() in file: |
| 35 | return file[word.upper()], None |
| 36 | else: |
| 37 | matches = get_close_matches(word, file.keys()) |
| 38 | if len(matches) > 0: |
| 39 | return f"Did you mean '{matches[0]}' instead?", matches[0] |
| 40 | else: |
| 41 | return "The word does not exist. Please double-check it.", None |
| 42 | |
| 43 | def on_search(): |
| 44 | word = entry.get().strip() |