pythonbuttonjupyter-notebookipywidgets

How do I change a button label created with 'interact_manual' from 'ipywidgets'? and how do I change the size and color of that button?


How do I change a button label created with 'interact_manual' from 'ipywidgets'? and how do I change the size and colour of that button?

Here is what I wrote

from ipywidgets import interact,interact_manual
def HDI_vs_CrimeRate():
    #do some thing here
interact_manual(HDI_vs_CrimeRate)

and here is how the button looks like:

Screenshot of resulting button

Thanks for your help


Solution

  • You may need to upgrade your ipywidgets; for me, your code returns a button with the label 'Run Interact', which is a little better than yours but not yet what you want.

    Assign your interact_manual to a variable, alter the description text of the child widget, and then call display() on your interact. This seems to get the job done, although there may be a more elegant way.

    from ipywidgets import interact, interact_manual
    def HDI_vs_CrimeRate():
        #do some thing here
    im = interact_manual(HDI_vs_CrimeRate)
    im.widget.children[0].description = 'changed'
    display(im)
    

    Edit: For color, you can use im.widget.children[0].style.button_color = 'red'.