-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (47 loc) · 1.89 KB
/
main.py
File metadata and controls
60 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import tkinter as tk
vocab = {
# Data goes here in the format "key (german word): value (english word), both are strings and don't forget the comma! Example:
"sehr interessiert, begeistert": "keen",
"apartheid": "apartheid"
# ...
}
class VocabularyTest:
def __init__(self, root):
self.root = root
self.root.title("English Vocabulary Test")
self.score = 0
self.current_index = 0
self.label = tk.Label(root, text="", font=("Arial", 12))
self.label.pack(pady=20)
self.entry = tk.Entry(root, font=("Arial", 12))
self.entry.pack()
self.button = tk.Button(root, text="Submit", command=self.check_answer)
self.button.pack(pady=10)
self.display_question()
def display_question(self):
if self.current_index < len(vocab):
german_word = list(vocab.keys())[self.current_index]
self.label.config(text=f"What is the English translation of '{german_word}'? ")
self.entry.pack() # Show entry field
self.button.pack() # Show submit button
else:
self.show_result()
def check_answer(self):
if self.current_index < len(vocab):
english_translation = vocab[list(vocab.keys())[self.current_index]]
user_answer = self.entry.get().strip().lower()
if user_answer in english_translation.lower():
self.score += 1
self.current_index += 1
self.entry.delete(0, "end")
self.display_question()
else:
self.show_result()
def show_result(self):
self.label.config(text=f"Test completed.\nYou scored {self.score} out of {len(vocab)}.")
self.entry.pack_forget() # Hide entry field
self.button.pack_forget() # Hide submit button
if __name__ == "__main__":
root = tk.Tk()
app = VocabularyTest(root)
root.mainloop()