add license
[tibetan_culture:learn_tibetan.git] / main.py
1 #    This program is free software: you can redistribute it and/or modify
2 #    it under the terms of the GNU General Public License as published by
3 #    the Free Software Foundation, either version 3 of the License, or
4 #    (at your option) any later version.
5 #
6 #    This program is distributed in the hope that it will be useful,
7 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
8 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 #    GNU General Public License for more details.
10 #
11 #    You should have received a copy of the GNU General Public License
12 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
13
14 from random import shuffle
15 from unicodedata import lookup
16 from Tkinter import *
17 from pygame import mixer
18 from tkSnack import *
19
20 letras = {lookup("tibetan letter ka"):("ka", "sound/ka.mp3"), 
21           lookup("tibetan letter kha"):("k'a", "sound/kha.mp3"),
22           lookup("tibetan letter ga"):("k_'a", "sound/kh_a.mp3"),
23           lookup("tibetan letter nga"):("nga", "sound/nga.mp3")}
24
25 # return random keys 
26 def shuffle_dictionary (dictionary):
27     # Python 3 
28     # keys =  list(dictionary.keys())
29     # Python 2 
30     keys = dictionary.keys()
31     shuffle(keys)
32     return keys
33         
34 def generate_question(list_questions):
35     right_answer = list_questions[0]
36     answers = list_questions[0:4]
37     shuffle(answers)
38     return right_answer, answers
39
40 def play_ogg():
41     mixer.init()
42     mixer.music.load('Example.ogg')
43     mixer.music.play()
44     
45 #print letras["ka"][0] # letra tibetana (importante poner el print)
46 #letras["ka"][1] # fichero de sonido
47
48 # random the letters
49 keys = shuffle_dictionary(letras)
50 right_answer, answers = generate_question(keys)
51 ventana = Tk()
52 initializeSnack(ventana)
53 ventana.geometry("185x260+100+80")
54 label = Label(ventana, text = right_answer, font=("", 80))
55 label.pack()
56
57 play_sound=Button(ventana,width=40,height=30,fg='black',
58             bitmap='snackPlay', command=play_ogg).place(x=5,y=102)
59 option_1 = Button(ventana,width=7,height=3,fg='black', 
60                   text=letras[answers[0]][0]).place(x=5,y=140) 
61 option_2 = Button(ventana,width=7,height=3,fg='black', 
62                   text=letras[answers[1]][0]).place(x=5,y=200) 
63 option_3 = Button(ventana,width=7,height=3,fg='black', 
64                   text=letras[answers[2]][0]).place(x=95,y=140)
65 option_4 = Button(ventana,width=7,height=3,fg='black', 
66                   text=letras[answers[3]][0]).place(x=95,y=200)
67
68 ventana.mainloop()