gpt4 book ai didi

python - Jupyter 笔记本 : How to change spacing between Text objects inside HBox?

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:17 25 4
gpt4 key购买 nike

假设我在 Jupyter Notebook 的一个单元格中有以下代码:

from ipywidgets.widgets import HBox, Text
from IPython.display import display

text1 = Text(description = "text1", width = 100)
text2 = Text(description = "text2", width = 100)
text3 = Text(description = "text3", width = 100)
text4 = Text(description = "text4", width = 100)
text5 = Text(description = "text5", width = 100)
display(HBox((text1, text2, text3, text4, text5)))

它产生以下输出:

enter image description here

如您所见,文本对象之间存在大量不必要的间距。如何更改间距以使它们留在单元格内?

最佳答案

似乎间距是由于 widget-text 的宽度造成的类被指定为宽度为 350 像素。尝试导入 HTML模块(即 from IPython.display import display, HTML )并插入 HTML('<style> .widget-text { width: auto; } </style>')进入细胞。

你应该得到这样的结果:

from ipywidgets.widgets import HBox, Text
from IPython.display import display, HTML

text1 = Text(description = "text1", width = 100)
text2 = Text(description = "text2", width = 100)
text3 = Text(description = "text3", width = 100)
text4 = Text(description = "text4", width = 100)
text5 = Text(description = "text5", width = 100)

display(HBox((text1, text2, text3, text4, text5)))
HTML('<style> .widget-text { width: auto; } </style>')

widgets styled with CSS

关于python - Jupyter 笔记本 : How to change spacing between Text objects inside HBox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38906333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com