Search code examples
pythonjupyter-notebookipywidgets

How do I set the width of the input field of an IntText widget in ipywidgets?


I create an IntText widget like this:

import ipywidgets as widgets
widgets.IntText(value=12, 
       description='CTR1_0', 
       style={'description_width': 'initial'})

When I include this widget in an HBox in a Tab, the text box is much larger than I need. How do I set it to be 10 characters?

enter image description here

There is no width parameter to IntText. I have tried adding width="10ch" to the style parameter do not work.


Solution

  • Create a Layout when you instantiate the button, and pass it as a layout= kwarg. You can hard code a pixel size, but probably not a character limit.

    import ipywidgets as widgets
    w = widgets.IntText(value=12, 
           description='CTR1_0', 
           style={'description_width': 'initial'},
           layout = widgets.Layout(width='100px')
    )
    # w.layout = widgets.Layout(width='100px')   # or set it later