增加下拉菜单的文本 - Python

Increase text of the dropdown menu - Python

我正在尝试在 Python 上使用以下代码创建下拉菜单。

pqrs = ['Segment1', 'Segment2', 'Segment3']

#Segment Criteria
Segment_selected = widgets.Text()
# print('=' * term_size.columns)
# print('\n' +"3[1m" + 'Select a Segment criteria for Selecting HCP Universe' + "3[0m")
# python code to run in jupyter notebook

from ipywidgets import interact, interactive, Layout
def lx(Segmentation):
    Segment_selected.value = str(Segmentation)
int_widget = interactive(lx, Segmentation=pqrs,)
int_widget.children[0].layout = Layout(width='400px',height = '40px')
display(int_widget)

这将生成以下输出: Code Output

现在,问题是我想在下拉列表的左侧显示完整的文本。在我的例子中它显示为“Segmentati ...”,我希望它在我的例子中是“Segmentation”。但是我做不到。

你能帮帮我吗?

最初评论宽度是固定的。您可以设置样式使其变大 - 这将减小小部件的整体其他尺寸:

pqrs = ['Segment1', 'Segment2', 'Segment3']

int_widget = interactive(lx, Segmentation=pqrs, )
int_widget.children[0].layout = Layout(width='auto',height = '40px')
int_widget.children[0].style = {'description_width': '200px'}  # increase size
display(int_widget)
 

获得:

这方面的基本文档是 here: Widget Styling#Description

尝试 "auto" or "initial" auto-fitting description_width