Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change button name on ipywidgets

Is there a way to easily change the button name in the ipywidgets module? I am using the decorator, but cannot find in the documentation how to change the name to something other than "Run Interact". I believe I need to use the decorator since my function needs to be run on demand and depends on multiple inputs from different widgets, but I'm open to other ways of doing so as well.

import ipywidgets as widgets
from IPython.display import display

@widgets.interact_manual(number1 = widgets.Dropdown(
                                            options=[1,2],
                                            description='select a number'),
                         number2 = widgets.Dropdown(
                                            options=[3,4],
                                            description='select another number'))
def add_numbers(number1,number2):
    return number1+number2
like image 572
kashmoney Avatar asked Jan 27 '23 17:01

kashmoney


1 Answers

A bit quick and dirty but you can set

widgets.interact_manual.opts['manual_name'] = 'Your text here'

before defining your function and this should change the label name. If you have multiple interact_manual calls that need different labels you will need to change it each time.


import ipywidgets as widgets
from IPython.display import display

widgets.interact_manual.opts['manual_name'] = 'Your text here'

@widgets.interact_manual(number1 = widgets.Dropdown(
                                            options=[1,2],
                                            description='select a number'),
                         number2 = widgets.Dropdown(
                                            options=[3,4],
                                            description='select another number'),)
def add_numbers(number1,number2):
    return number1+number2
like image 120
ac24 Avatar answered Jan 31 '23 13:01

ac24