前に和歌集のQ&Aを作りましたが、これに現代訳とかの要素(value)を追加すると辞書では簡単ではない。
何故かと云うと辞書はキーとvalueがペアーになっているので、valueを複数にすると複雑になります。
そこで原始的ではありますが、リストにキーと二つの要素を書き込み、乱数で三つ(キー+要素二個)を取り出しEntryボックスに表示する簡単な方法を編み出しました。 keyと二つの要素で一組と考え、乱数でその組を指定して書き出します。 中々快調に動いてます。
何か良い方法がないかネットで探してみましたが行き当たりませんでしたので、こんな方法もありますという意味でアップしておきます。 自分の為ですがね。
1 | #辞書はvalueが複数あると使えない 4/24/2020 | |
2 | #リストに複数要素あり.py OK! | |
3 | ||
4 | import tkinter as tk | |
5 | import random | |
6 | ||
7 | root=tk.Tk() | |
8 | root.title(‘英単語Q&A’) | |
9 | root.geometry(“400×200”) | |
10 | ||
11 | txt1=tk.Entry(root, width=50) | |
12 | txt1.place(x=50,y=10) | |
13 | ||
14 | txt2=tk.Entry(root, width=30) | |
15 | txt2.place(x=50,y=40) | |
16 | ||
17 | txt3=tk.Entry(root, width=50) | |
18 | txt3.place(x=50,y=70) | |
19 | ||
20 | ||
21 | list = ( | |
22 | “auspicious”,”吉兆の”,”auspicious beginning 幸先の良いスタート”, | |
23 | “nauseous”,”むかつかせる”,”become/feel nauseous 吐き気を催す”, | |
24 | “beseech”,”懇願[嘆願]する”,”beseech him to show mercy 彼に慈悲を嘆願する”, | |
25 | “canny”,”用心深い”,”canny about ~を見抜く”, | |
26 | “carping”,”あら捜し”,”carping tongue 毒舌”, | |
27 | “commodious”,”家・室が広い”,”commodious apartment”, | |
28 | “condign”,”(処罰が)至当の”,”condignity 功徳”, | |
29 | “demarcation”,”境界(設定)”,”demarcation line between ~間の垣根”, | |
30 | “denize”,”居住者、居留民、帰化動物”,”denizens of the deep 海の住人、魚”, | |
31 | “derogatory”,”傷つける”,”derogatory implications 軽蔑的な意味合い”, | |
32 | “diaphanous”,”透明な、半透明の”,”diaphanous curtain 透けて見えるカーテン”, | |
33 | “dingy”,”黒ずんだ”,”digny building”, | |
34 | “fete”,”(…のために)祝う”,”fete day 祭日”, | |
35 | ) | |
36 | ||
37 | def show_data(): | |
38 | ||
39 | l=len(list) | |
40 | l=l/3 | |
41 | ||
42 | ||
43 | n = random.randrange(0,l,3)#n=12迄出る。# (0,l,3)のlは1ではなくL(の小文字)です。行40のlです。 | |
44 | print(n) | |
45 | ||
46 | list[n] | |
47 | txt1.delete(0,tk.END) | |
48 | txt1.insert(tk.END,list[n*3]) | |
49 | ||
50 | list[n*3+1] | |
51 | txt2.delete(0,tk.END) | |
52 | txt2.insert(tk.END,list[n*3+1]) | |
53 | ||
54 | list[n*3+2] | |
55 | txt3.delete(0,tk.END) | |
56 | txt3.insert(tk.END,list[n*3+2]) | |
57 | ||
58 | ||
59 | def quit(): | |
60 | root.destroy() | |
61 | ||
62 | ||
63 | btn1=tk.Button(root,text=”Next”, command=show_data) | |
64 | btn1.place(x=100, y=130) | |
65 | ||
66 | btn2=tk.Button(root, text=”End”, command=quit) | |
67 | btn2.place(x=200, y=130) | |
68 | ||
69 | root.mainloop() |
runするとこうなります。