Return argument for widget button

Hi,

I was wondering whether the on_click method of the widget.button can return something. I tried to simply add a

return X

at the end of the function and read the returned value but that does not seem to be working.
is there some way to implement that?

Aff

Hi @AffDk,

what is your intention, why should the on_click method return a value?

Cheers

I could imagine of some scenarios in which it would be useful to have such a functionality.
For example, I want to read an image file and then return it as a variable. I am not saying that you could not have other ways of doing it but it would be cool if on_click returns something. or at least change a variable content “in-place” when the on_click method is executed.

cheers

Hey there,

in this notebook I use on_click events to run functions. And those functions can do pretty much anything you want.

...
def on_btn_doc_clicked(b):
    output.clear_output()
    input_img.clear_output()
    with output:
        display(HTML(DOC[lang]))
        
def on_data_change(change):
    output.clear_output()
    input_img.clear_output()
    start = time.time()
    img = PILImage.create(btn_upload.data[-1])
    end = time.time()
    if VERBOSE: print('took', end-start, 'for loading the image')
    outputImage(img)
    btn_upload._counter = 0
...
# adding events
btn_doc.on_click(on_btn_doc_clicked)
btn_upload.observe(on_data_change, names=['data'])
dpd_lang.observe(on_lang_select)
dpd_kind.observe(on_kind_select)
...