0

I am creating a post form that will send my input as dictionary to a server. I planned to display the user entered input in a TextArea with my first display button click. This display button sets the next button (Send) to be visible. The Send button then convert or saves the values to a dictionary (key/value pair).

In my code, i followed the example in the ipywidget documentation (https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html [cell 12]) by adding all my widgets in a list. I am have difficulty in calling the values of the widget items to display in the Text area

I have tried to access the values using children[0].values but get error each time. AttributeError: 'Button' object has no attribute 'values'. I will appreciate anyone's help to do this form. If i can get my inputs as a dictionary, that will be very helpful


from ipywidgets import Layout, Button, Box, FloatText, Textarea, Dropdown, Label, IntSlider, Text

#Form item layout
form_item_layout = Layout(
    display='flex',
    flex_flow='row',
    justify_content='space-between'
)


#form container
form_items = [
    Box([
        Label(value='Name'),
        Text(value='John')
        ], layout=form_item_layout),


   Box([
       Label(value='Collection UUID'),
        Dropdown(options=['theme', 'play', 'character'])
       ], layout=form_item_layout),

    Box([Label(value='Result'),
          Textarea(rows = 20)], layout=form_item_layout),

    Button(description="display"), 
    Button(description="Send", button_style='success')

]


#box layout that holds the forms
box_lyt = Layout(
    display='flex',
    flex_flow='column',
    border='solid 2px',
    align_items='stretch',
    width='50%'
)

form = Box(children=form_items, layout=box_lyt)
display(form)
form.children[4].layout.visibility = 'hidden'



def show(b):
    form.children[4].layout.visibility = 'visible'
    form.children[2] = c.children[0] + c.children[1] + c.children[2]





#Convert textarea values to dictionary
def list_children(c):
    return c.children[2].to_dict()

form.children[3].on_click(show)
form.children[4].on_click(list_children )

I expect a widget displaying: Name, ID, result and display button. Clicking the display should show the values in the result TextArea and make the button (send) visible. Clicking the Send button should accept these values from result and save as dictionary. The widget displays but is not responsiveenter image description here

Stringz
  • 43
  • 1
  • 1
  • 8
  • Can you help me understand your question a little more? If I type 'John', and select 'theme' as Collection, then click display, what should appear in the Result box? Something like {'John': 'theme'}? – ac24 May 03 '19 at 07:35
  • @ac24 Thanks for responding, I expect the values (john and theme) that you typed to be displayed in the box. Then the second button post the values in the display to some server. – Stringz May 04 '19 at 13:45
  • @ac24, yes but the keys can be any name with the values entered. E.g {'A': 'John', 'B' : 'theme'} – Stringz May 04 '19 at 18:09

0 Answers0