Sure! Below is a Python application built using CustomTkinter that helps you learn Greek by allowing you to input English and Greek word pairs. The application features:
- Two Columns: English on the left and Greek on the right.
- Multiple Rows: You can add as many word pairs as you need.
- Auto-Focus Navigation: Pressing
Enter in one entry field shifts the focus to the corresponding field, making data entry seamless.
Prerequisites
-
Python 3.x: Ensure you have Python installed. You can download it from python.org.
-
CustomTkinter: Install the CustomTkinter library using pip:
pip install customtkinter
Complete Code
import customtkinter as ctk
import tkinter as tk
# Set the appearance mode and color theme
ctk.set_appearance_mode("System") # Modes: "System" (default), "Dark", "Light"
ctk.set_default_color_theme("blue") # Themes: "blue" (default), "green", "dark-blue"
class GreekLearningApp(ctk.CTk):
def __init__(self, rows=10):
super().__init__()
self.title("Greek Learning App")
self.geometry("600x400")
self.resizable(False, False)
# Create header labels
header_frame = ctk.CTkFrame(self)
header_frame.pack(pady=10)
ctk.CTkLabel(header_frame, text="English", width=200, anchor="center", font=("Arial", 16)).grid(row=0, column=0, padx=10)
ctk.CTkLabel(header_frame, text="Greek", width=200, anchor="center", font=("Arial", 16)).grid(row=0, column=1, padx=10)
# Frame to hold the entry rows
self.entries_frame = ctk.CTkFrame(self)
self.entries_frame.pack(pady=10)
self.entries = [] # To store tuples of (english_entry, greek_entry)
for i in range(rows):
english_entry = ctk.CTkEntry(self.entries_frame, width=200, placeholder_text="Enter English word")
greek_entry = ctk.CTkEntry(self.entries_frame, width=200, placeholder_text="Enter Greek translation")
english_entry.grid(row=i, column=0, padx=10, pady=5)
greek_entry.grid(row=i, column=1, padx=10, pady=5)
self.entries.append((english_entry, greek_entry))
# Bind the Return (Enter) key to navigate between entries
english_entry.bind("<Return>", lambda event, row=i: self.focus_greek(row))
greek_entry.bind("<Return>", lambda event, row=i: self.focus_next_english(row))
def focus_greek(self, row):
"""
When Enter is pressed in the English entry, focus moves to the Greek entry in the same row.
"""
greek_entry = self.entries[row][1]
greek_entry.focus()
def focus_next_english(self, row):
"""
When Enter is pressed in the Greek entry, focus moves to the next English entry.
If it's the last row, it loops back to the first.
"""
next_row = row + 1
if next_row >= len(self.entries):
next_row = 0 # Loop back to first row if at the end
english_entry = self.entries[next_row][0]
english_entry.focus()
if __name__ == "__main__":
app = GreekLearningApp(rows=10) # You can adjust the number of rows as needed
app.mainloop()
How It Works
-
Layout:
- The app window has a header with two labels: "English" and "Greek."
- Below the headers, there are multiple rows (default 10) each containing two entry fields: one for English and one for Greek.
-
Entry Navigation:
- From English to Greek: When you type a word in the English entry and press
Enter, the focus automatically shifts to the corresponding Greek entry.
- From Greek to Next English: After typing in the Greek entry and pressing
Enter, the focus moves to the next English entry. If you're on the last row, it loops back to the first English entry.
-
Customization:
- Number of Rows: You can adjust the
rows parameter when instantiating GreekLearningApp to have more or fewer word pairs.
- Appearance: Customize the appearance by changing the
appearance_mode and color_theme using ctk.set_appearance_mode() and ctk.set_default_color_theme().
Running the Application
-
Save the above code to a file, for example, greek_learning_app.py.
-
Open your terminal or command prompt and navigate to the directory containing the file.
-
Run the application using:
python greek_learning_app.py
Screenshots
While I can't provide actual screenshots here, the interface will look something like this:
------------------------------------------
| English | Greek |
------------------------------------------
| [ English Entry ] | [ Greek Entry ] |
| [ English Entry ] | [ Greek Entry ] |
| ... | ... |
------------------------------------------
Additional Features (Optional)
To extend the functionality of this app, consider adding:
- Save and Load: Ability to save the entered word pairs to a file and load them later.
- Flashcard Mode: A mode to test yourself by showing English words and requiring you to input the Greek translation, and vice versa.
- Validation: Check if the Greek translations are correct (requires a database or API).
- Styling Enhancements: Improve the UI with better styling, fonts, and colors.
Feel free to modify and enhance the application to better suit your learning needs!