0
下のコードの2番目のドロップダウンオプションから選択したドロップダウンリストの値を読み込もうとしています。 [例:「ドイツ」、「フランス」、「スイス」]Python-tkinter 2番目のドロップダウン値の読み方
ここで私)楽しいと呼ばれる関数を(使用して値最初のドロップダウンを読むことができることができます
しかし、同じことが第二のドロップを読み取ることができませんダウン値。
は、ここでは、コードがどのように以下のコードから値2番目のドロップダウンを読むために私を提案します。
import sys
if sys.version_info[0] >= 3:
import tkinter as tk
else:
import Tkinter as tk
class App(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.dict = {'Asia': ['Japan', 'China', 'Malaysia'],
'Europe': ['Germany', 'France', 'Switzerland']}
self.variable_a = tk.StringVar(self)
self.variable_b = tk.StringVar(self)
self.variable_a.trace('w', self.update_options)
self.optionmenu_a = tk.OptionMenu(self, self.variable_a, *self.dict.keys(), command=self.fun)
self.optionmenu_b = tk.OptionMenu(self, self.variable_b, '')
self.variable_a.set('Asia')
self.optionmenu_a.pack()
self.optionmenu_b.pack()
self.pack()
def fun(self,value):
print(value)
def update_options(self, *args):
countries = self.dict[self.variable_a.get()]
self.variable_b.set(countries[0])
menu = self.optionmenu_b['menu']
menu.delete(0, 'end')
for country in countries:
menu.add_command(label=country, command=lambda nation=country: self.variable_b.set(nation))
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
app.mainloop()
感謝を迅速に対応するために.... それは魅力のように働いていた.... !! – Shanky