[IPython-dev] How to set state of widget in IPython3?
Mark Bakker
markbak at gmail.com
Tue Mar 24 11:52:24 EDT 2015
Thanks, Kiko.
I should have noticed that the 'values' keyword had changed to the much
better 'options' keyword in IPython3.
Got a follow up question if you don't mind. When I use the same example,
but with RadioButtons rather than a Dropdown widget, the radio buttons
overlap with the descriptor (Line Color:). Any way to specify the distance
between the descriptor and radio buttons? I think the default should
probably not overlap the two. Here's an example:
w = widgets.RadioButtons(
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);
From: Kiko <kikocorreoso at gmail.com>
> Subject: Re: [IPython-dev] How to set state of widget in IPython3?
> To: IPython developers list <ipython-dev at scipy.org>
> Message-ID:
> <
> CAB-sx61bM7o+SU5jETDGhco9O1vt3EMvO6_ThR5WPvrmzO6snA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150324/93e5d019/attachment.html>
More information about the IPython-dev
mailing list