Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

widget layout when using interact

Tags:

ipython

widget

How can I use a container widget to control the layout while using interact? For instance, I'd like those 2 Select to be in a HBox.

from IPython.html import widgets
from IPython.display import display

def f(dl, ft):
    print dl, ft

dlW = widgets.Select(options={str(k):k for k in  range(4)})
ftW = widgets.Select(options={str(k):k for k in  'ABCD'})
hbox=widgets.HBox([dlW, ftW])
i = widgets.interact(f,
                 dl = dlW,
                 ft = ftW
                )

# display( hbox ) # <-- commenting in makes the widget display twice
like image 978
ILoveCoding Avatar asked May 20 '26 09:05

ILoveCoding


1 Answers

Found a solution using interactive instead of interact

dlW = widgets.Select(options={str(k):k for k in  range(4)})
ftW = widgets.Select(options={str(k):k for k in  'ABCD'})
i = widgets.interactive(f,
             dl = dlW,
             ft = ftW
            )

hbox=widgets.HBox(i.children)
display( hbox )
like image 68
ILoveCoding Avatar answered May 26 '26 23:05

ILoveCoding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!