Reputation: 2981
How can I configure the ipywidgets
Checkbox for long text strings as in,
c = Checkbox(description=' this is some very long very long text',value=False)
and not get the text to be squeezed and wrapped in the encompassing Jupyter notebook?
Thanks!
Upvotes: 7
Views: 5567
Reputation: 3479
Use this to set the width to the left of the checkbox and also set the overall width independently
import ipywidgets as widgets
c = widgets.Checkbox(
description=' this is some very long very long text',
value=False)
c.style = {'description_width': '0px'} # sets the width to the left of the check box
c.layout.width = 'auto' # sets the overall width check box widget
c
Upvotes: 1
Reputation: 323
Simply use this:
import ipywidgets as widgets
c = widgets.Checkbox(
description='This is some very long very long text',
value=False,
layout=widgets.Layout(width='100%'))
Upvotes: 4
Reputation: 17339
Another option is to bundle it with Label
:
from ipywidgets import widgets, Layout
from IPython.display import display
checkbox = widgets.Checkbox(value=False, disabled=False, layout=Layout(width='30px'))
label = widgets.Label('description', layout=Layout(width='500px', margin='6px 0 0 -10px'))
box = widgets.HBox([checkbox, label])
display(box)
Upvotes: 1
Reputation: 2981
Put this is the cell with the checkbox
from IPython.display import display, HTML
HTML('<style> .widget-hbox .widget-label { max-width:350ex; text-align:left} </style>')
and it'll change the widths and alignment.
Upvotes: 0