dj *_*j K 5 python jupyter-notebook ipywidgets
我正在使用 aipywidgets.Label在笔记本中显示文本。基本问题,如何更改文本对齐方式Label?它似乎是左对齐的,我希望它是右对齐的。我确实在文档中寻找过它,但找不到它。
谢谢
RZin 的答案有点有效,但它实际上并没有对齐文本——它只是移动包含文本的框。
可以这样对齐标签文本:
Label("LABEL", layout=Layout(display="flex", justify_content="flex-start")
用于"flex-start"左对齐、"center"居中对齐和"flex-end"右对齐。还有和。"space-between""space-around"
可以复制并粘贴到笔记本中的完整示例:
from ipywidgets import Label, Layout, HBox
from IPython.display import display
x = Label("Align Left", layout=Layout(display="flex", justify_content="flex-start", width="30%", border="solid"))
y = Label("Align Center", layout=Layout(display="flex", justify_content="center", width="30%", border="solid"))
z = Label("Align Right", layout=Layout(display="flex", justify_content="flex-end", width="30%", border="solid"))
display(HBox([x,y,z]))
Run Code Online (Sandbox Code Playgroud)
我有类似的问题并用 VBox 小部件包装了我的标签。
from ipywidgets import VBox, Label, Layout
VBox([Label('I want this to be in the center.')]
,layout=Layout(width='100%', display='flex' ,
align_items='center'))
Run Code Online (Sandbox Code Playgroud)