python ipywidgets force a summit programmatically in a widgets.Text

165 views Asked by At

I habe a widgettext in a notebook as follows:

myinput = widgets.Text(value='', palceholder='introduce your number')
        
def myinput_handler(sender):
    '''

    '''
    #do something
    
    
myinput.on_submit(myinput_handler)

# button
my_btn = widgets.Button(description='LOAD')
        
def my_btn_handler(change):
    
    if len(myinput.value) == '':
        my_input.value = 3333
    else:
        dossier = myinput.value 
       
    ##### ---> RUN myinput_handler(sender)
    
    
my_btn.on_click(my_btn_handler)

basically What I would like to find is the way to run the same code as if the widget text would be submitted, but clicking a button

any idea there?

1

There are 1 answers

0
ac24 On BEST ANSWER

Given that observe just passes through the widget when the function is run, couldn't you just run your handler function and pass the widget directly as an argument to replicate submitting?

import ipywidgets as widgets

myinput = widgets.Text(value='', placeholder='introduce your number')
        
def myinput_handler(sender):
    print(sender.value)
    
    
myinput.on_submit(myinput_handler)
display(myinput)

# button
my_btn = widgets.Button(description='LOAD')
        
def my_btn_handler(change):
    
    if len(myinput.value) == 0:
        myinput.value = '3333'
    else:
        dossier = myinput.value
       
    myinput_handler(myinput)
    
    
my_btn.on_click(my_btn_handler)
display(my_btn)