【问题标题】:How to get wider text for Checkbox widget?如何为 Checkbox 小部件获取更宽的文本?
【发布时间】:2016-10-06 20:23:11
【问题描述】:

如何为长文本字符串配置ipywidgets复选框,

 c = Checkbox(description=' this is some very long very long text',value=False)

而不是让文本被压缩并包裹在包含的 Jupyter 笔记本中?

谢谢!

【问题讨论】:

    标签: jupyter-notebook ipywidgets


    【解决方案1】:

    另一种选择是将其与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)
    

    【讨论】:

      【解决方案2】:

      这是带有复选框的单元格

      from IPython.display import display, HTML
      HTML('<style> .widget-hbox .widget-label { max-width:350ex; text-align:left} </style>')
      

      它会改变宽度和对齐方式。

      【讨论】:

        【解决方案3】:

        只需使用这个:

        import ipywidgets as widgets
        
        c = widgets.Checkbox(
            description='This is some very long very long text',
            value=False,
            layout=widgets.Layout(width='100%'))
        

        【讨论】:

          【解决方案4】:

          使用它来设置复选框左侧的宽度,并独立设置整体宽度

          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
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-08-29
            • 2023-04-10
            • 2012-04-16
            • 2019-06-11
            • 2015-05-10
            • 2019-05-25
            • 2019-03-10
            • 2011-09-04
            相关资源
            最近更新 更多