Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: 1 Thanks for your help

like image 465
MehranYazdizadeh Avatar asked Jul 15 '18 08:07

MehranYazdizadeh


People also ask

What is Python Ipywidgets?

ipywidgets, also known as jupyter-widgets or simply widgets, are interactive HTML widgets for Jupyter notebooks and the IPython kernel. Notebooks come alive when interactive widgets are used. Users gain control of their data and can visualize changes in the data. Learning becomes an immersive, fun experience.

What does @interact do in Python?

The interact function ( ipywidgets. interact ) automatically creates user interface (UI) controls for exploring code and data interactively. It is the easiest way to get started using IPython's widgets.


1 Answers

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'.

like image 175
ac24 Avatar answered Sep 28 '22 07:09

ac24