Is there a way to control the placement and alignment of ipywidgets (inside jupyter notebook)?
from ipywidgets import widgets
from IPython.display import Javascript, display
event_type_ui = widgets.Text(value='open', description='Test Event')
platform_ui = widgets.Text(value='Android', description='Control Event')
display(event_type_ui)
display(platform_ui)
I would like to specify an offset (in pixels?) to allow the label to fit and to have two controls aligned vertically.
The layout and styling documentation for
ipywidgets
says:I was able to coax it into aligning the labels:
from ipywidgets import Text, HBox, VBox, Box from IPython.display import display widget1 = Text(value='Cats', description='Test Event', layout='margin-right:5px') widget2 = Text(value='Oranges', description='Another Test Event') widget1.width = '200px' widget2.width = '150px' display(VBox([widget1, widget2]))
to produced this:
But in general, I doesn't seem like we can directly target layout properties of the description label, just the entire widget itself.
The ipywidgets also have an add_class that can be used for getting into the weeds when you really need it:
After some fiddling, I was able to get this:
Before:
After:
Here is a copy-paste snippet, if interested: