ライブラリでキーワードを検索するプログラムがあります。 は、現在、それはしかし、私は私が私が現在で探しています何辞書変更するには、ラジオボタンを使用してノートの異なるセットを引っ張って別の辞書を選択することができるようになる機能を追加したい素晴らしい作品と呼ばれてラジオボタンが選択されているかどうかに応じて別の辞書を検索する
辞書:。
rms_notes = { "SomeKey" : "Some random notes" }
vzt_notes = { "SomeKey" : "Some random notes" }
nsr_notes = { "SomeKey" : "Some random notes" }
私のRadioButtonsは以下の通りです。
keywordEntry = Entry(root)
keywordEntry.bind('<Return>', kw_entry)
KeywordEntry.place(#all the formatting here)
そして、次のように私はラジオボタンが選択されている間、それぞれ異なる辞書にアクセスするために使用する機能は次のとおりです:
v1 = IntVar()
def kw_entry(event=None):
libvar = v1.get()
e1Current = keywordEntry.get().lower()
if libvar == 1:
if e1Current in rms_notes:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, rms_notes[e1Current])
root.text.see(tkinter.END)
else:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, "Not a Keyword")
root.text.see(tkinter.END)
elif libvar == 2:
if e1Current in vzt_notes:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, vzt_notes[e1Current])
root.text.see(tkinter.END)
else:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, "Not a Keyword")
root.text.see(tkinter.END)
elif libvar == 3:
if e1Current in nsr_notes:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, nsr_notes[e1Current])
root.text.see(tkinter.END)
else:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, "Not a Keyword")
root.text.see(tkinter.END)
else:
root.text.delete(1.0, END)
root.text.insert(tkinter.END, "No Library select")
root.text.see(tkinter.END)
この今、私のライブラリを使用して呼ばれているため
RaBu1 = tkinter.Radiobutton(root,text="Lib1",variable = vl, value = 1)
RaBu2 = tkinter.Radiobutton(root,text="Lib2",variable = vl, value = 2)
RaBu3 = tkinter.Radiobutton(root,text="Lib3",variable = vl, value = 3)
RaBu1.place(#all the formatting here)
RaBu2.place(#all the formatting here)
RaBu3.place(#all the formatting here)
どのように私は期待して動作しますが、私はこの関数に各辞書を呼び出すためのより良い方法があるのだろうか?より短いコードでこのタスクを実行するためのよりクリーンな方法があるように感じるだけです。
私は間違っているかもしれませんが、誰かがいくつかのアイデアを持っているか、問題に入力していただければ幸いです。