【发布时间】:2015-08-04 14:31:00
【问题描述】:
如何左对齐而不是右对齐 iPython 3 小部件(例如 IntSlider)中的标签?我的最终目标是左对齐一组带标签的小部件。这需要左对齐它们的标签,因为标签是每个小部件的最左边的元素。
我已经阅读了 Aligning TextBox Widgets in IPython Notebooks,但是 (a) 它专注于为右对齐标签腾出更多空间,并且 (b) 提议的解决方案似乎不会影响标签宽度。 (顺便说一句,我有兴趣找到可以重置最小标签宽度的单元格可执行代码。)
我也阅读了Change the size of the label in an IPython notebook widget 中的讨论,但似乎没有提供简单的解决方案。
感谢您的帮助。
附录(2015-06-02):
看起来 widget.interactive() 不能很好地与 Jakob 建议的解决方案配合使用。示例:
from IPython.html import widgets
from IPython.display import display
def mySlider(text='', twidth=100, min=0, max=10, value=5):
c1 = widgets.HBox()
ints = widgets.IntSlider(min=min, max=max, value=value)
text = widgets.HTML(text, width=twidth)
c1.children = (text, ints)
return c1
s1 = mySlider('Test')
s2 = mySlider('TestTest')
s3 = mySlider('TestTestTest')
def process(a, b, c):
print([a, b, c])
widgets.interactive(
process,
a=s1.children[1].value,
b=s2.children[1].value,
c=s3.children[1].value
)
以通常的对齐方式生成滑块标签 a、b、c。
【问题讨论】:
标签: widget alignment label ipython-notebook