2016-07-12 4 views
0

私は、ドロップダウンウィジェットの選択されたオプションに応じて、テキストボックスウィジェットの説明を変更したいと考えています。私はリストの辞書を使ってこれを達成できると思った。これは私がやったことの一例です:ドロップダウンウィジェットの選択したオプションに応じて、テキストボックスウィジェットの説明を変更するにはどうすればよいですか? (List of Lists)

#Lists of text box descriptions 
LEF_SOL = ['AMP','DEP','LAGTIME'] 
INI_SOL = ['AMP','DEP','XWavemaker'] 
INI_REC = ['Xc','Yc','WID'] 

# dictionary made with such lists 
wave_options = {'left boundary solitary':LEF_SOL, 
      'initial solitary wave':INI_SOL,'rectangular hump':INI_REC} 

#dropdown widget of the dictionary 
wave_maker = widgets.Dropdown(options=wave_options) 

# Textbox 1 description = first object of list depending on the dropdown 
first_option = widgets.BoundedFloatText(width = "20%",height = '50px', 
          description = wave_maker.value[0]) 

# Textbox 2 description = second object of list depending on the dropdown 
second_option = widgets.BoundedFloatText(width = "20%",height = '50px', 
          description = wave_maker.value[1]) 

# Textbox 3 description = third object of list depending on the dropdown 
third_option = widgets.BoundedFloatText(width = "20%",height = '50px', 
          description = wave_maker.value[2]) 

display(wave_maker,first_option,second_option,third_option) 

しかし、私はこれを実行すると、テキストボックスの説明は、ドロップダウンリストに表示され、最初のオプションに属するものであることとどまります。ドロップダウンが変更された場合、それらを変更します。私はこれが 'リンク'でできることを知っています。しかし、エラーが発生し

link((wave_maker,'value[0]'), (first_option, 'description')) 
link((wave_maker,'value[1]'), (second_option, 'description')) 
link((wave_maker,'value[2]'), (third_option, 'description')) 

::私はへの 'リンク' に変更する場合

TypeError: <ipywidgets.widgets.widget_selection.Dropdown 
object at 0x7fd47bbbd790> has no trait 'value[0]' 

はまだ:

link((wave_maker,'value'), (first_option, 'description')) 

を、このエラーが表示されます。

をそれは次のようになります
TraitError: The 'description' trait of a BoundedFloatText 
instance must be a unicode string, but a value of ['AMP', 'DEP', 'XWavemaker'] 
<type 'list'> was specified. 

これを解決する方法はありますか?

答えて

0

私の質問に対する解決策は、「観察」または「相互作用」を使用して行うことができます。私は「観察」の例を添付しました:

​​
関連する問題