5

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!

reckoner
  • 2,861
  • 3
  • 33
  • 43

4 Answers4

2

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%'))
Marcus
  • 275
  • 1
  • 12
1

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)
Dennis Golomazov
  • 16,269
  • 5
  • 73
  • 81
1

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
DougR
  • 3,196
  • 1
  • 28
  • 29
0

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.

reckoner
  • 2,861
  • 3
  • 33
  • 43