我正在使用 ipywidgets.Label
在笔记本中显示文本。
基本问题,如何更改 Label
中的文本对齐方式?它似乎是左对齐的,我希望它是右对齐的。我真的在文档中寻找它,但我找不到它。
谢谢
最佳答案
RZin 的回答有点用,但是它实际上并没有对齐文本——它只是移动了包含文本的框。
可以这样对齐标签文本:
Label("LABEL", layout=Layout(display="flex", justify_content="flex-start")
"flex-start"
用于左对齐,"center"
用于中心对齐,"flex-end"
用于右对齐。有also "space-between"
and "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]))
关于python - 在 Ipywidget 中更改 Label 内容的对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58416763/