kashmoney
kashmoney

Reputation: 442

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

Upvotes: 5

Views: 2431

Answers (1)

ac24
ac24

Reputation: 5565

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

Upvotes: 9

Related Questions