-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtango.py
More file actions
109 lines (96 loc) · 4.81 KB
/
tango.py
File metadata and controls
109 lines (96 loc) · 4.81 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from os import name
import tkinter as tk
from tkinter import messagebox
import tango_dict_make as tdm
tango_dict = tdm.make()
print(tango_dict)
length = len(list(tango_dict.values()))
class Application(tk.Frame):
def __init__(self, master = None, tango_dict=tango_dict):
self.count = 0
self.entry_user = tk.Entry()
tk.Frame.__init__(self, master)
self.master.geometry("250x380")
self.pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.display_word()
self.createWidgets()
self.display_result()
def display_word(self):
self.text = tk.StringVar()
self.text.set(list(tango_dict.keys())[self.count])
self.label = tk.Label(textvariable=self.text)
self.label.pack()
def display_result(self):
self.text_judge = tk.StringVar()
self.text_judge.set("")
self.label_judge = tk.Label(textvariable=self.text_judge)
self.label_judge.pack()
def callback(self,i):
print(str(i)+"is clicked")
self.num = str(i)
def createWidgets(self):
tk.Label(text="How to read this tango?", font=("System",12)).pack()
self.entry_user.pack()
tk.Label(text="What type is the accent?", font=("System",12)).pack()
self.btn0 = tk.Button(text='0', command=lambda:[self.callback(0.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn1 = tk.Button(text='1', command=lambda:[self.callback(1.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn2 = tk.Button(text='2', command=lambda:[self.callback(2.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn3 = tk.Button(text='3', command=lambda:[self.callback(3.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn4 = tk.Button(text='4', command=lambda:[self.callback(4.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn5 = tk.Button(text='5', command=lambda:[self.callback(5.0),self.judge()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn_Next = tk.Button(text='Next', command=lambda:[self.change_word()], height=1,width=10,bg = "blue").pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn_Next = tk.Button(text='Back', command=lambda:[self.back_word()], height=1,width=10,bg = "blue").pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
self.btn_Kaito = tk.Button(text='Knowledge', command=lambda:[self.show_kaitou()], height=1,width=10).pack(expand = 1, fill = tk.BOTH, anchor = tk.NW)
def judge(self):
entry_user = self.entry_user.get()
print(entry_user)
print(list(tango_dict.values())[self.count])
if entry_user == list(tango_dict.values())[self.count][0] \
and self.num == list(tango_dict.values())[self.count][1]:
self.text_judge.set("Congratulations!!")
print("Congratulations!!")
elif entry_user != list(tango_dict.values())[self.count][0] \
and self.num == list(tango_dict.values())[self.count][1]:
print("Read wrong!")
self.text_judge.set("Read wrong!")
elif entry_user == list(tango_dict.values())[self.count][0] \
and self.num != list(tango_dict.values())[self.count][1]:
print("Accent wrong!")
self.text_judge.set("Accent wrong!")
else:
print("Read/Accent both wrong!")
self.text_judge.set("Read/Accent both wrong!")
def change_word(self):
if self.count < length - 2:
self.label.configure(background='white')
self.count += 1
self.text.set(list(tango_dict.keys())[self.count])
self.text_judge.set("")
self.entry_user.delete(0, tk.END)
elif self.count == length - 2:
self.count += 1
self.text.set("Finish")
self.label.configure(background='red')
self.text_judge.set("Everything is done!")
else:
pass
def back_word(self):
if self.count > 0:
self.label.configure(background='white')
self.count -= 1
self.text.set(list(tango_dict.keys())[self.count])
self.text_judge.set("")
self.entry_user.delete(0, tk.END)
elif self.count == 0:
self.count -= 1
self.text.set("Nothing to back.")
self.label.configure(background='red')
self.text_judge.set("Everything is done!")
else:
pass
def show_kaitou(self):
messagebox.showinfo('Reference', list(tango_dict.values())[self.count][2])
if __name__ == "__main__":
root = tk.Tk().title("TangoChou")
app = Application(master = root)
app.mainloop()