[IPython-dev] How to set state of widget in IPython3?

Kiko kikocorreoso at gmail.com
Tue Mar 24 10:19:36 EDT 2015


2015-03-24 12:51 GMT+01:00 Mark Bakker <markbak at gmail.com>:

> Hello list. I am trying to set the state of a DropdownWidget (Or
> RadioButton) in IPython3. You didn't have to do that in the past, but even
> if I specify the value, it gives me an error. Simple example:
>
> This works:
>
> def plot_line(c='b'):
>     plt.plot([0,1],color=c)
> interact(plot_line,c=['b','r','g']);
>
> This works in IPython2, but not in IPython3. In IPython3 it passes c=None
> to the function on initialization.
>
> def plot_line(c='b'):
>     plt.plot([0,1],color=c)
> interact(plot_line,c=DropdownWidget(values=['b','r','g']));
>
> Even when specifying the value, for example
>
> def plot_line(c='b'):
>     plt.plot([0,1],color=c)
> interact(plot_line,c=DropdownWidget(value='r',values=['b','r','g']));
>
> I get an error: KeyError: 'r'.
>
> Any thoughts on how to set the state when creating a DropwdownWidget (or
> RadioButtonWidget) using interact? Or is this a bug?
>

Hi, check this:
http://nbviewer.ipython.org/github/ipython/ipython/blob/master/examples/Interactive%20Widgets/Widget%20List.ipynb

In your example:
w = widgets.Dropdown(
    options=['b', 'r', 'g'],
    value='r',
    description='Line Color:',
)

def plot_line(c='b'):
    plt.figure()
    plt.plot([0,1],color=c)
interact(plot_line, c = w)


>
> Thanks,
>
> Mark
>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150324/8a02ff5f/attachment.html>


More information about the IPython-dev mailing list