Jupyter 小部件格式

问题描述 投票:0回答:1

我正在使用以下代码:

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

def f(x):
    return x

interact_manual(f, x='Hi there!');

它会在笔记本中生成以下小部件:

问题是文本框有一个固定的默认大小,非常小,我想增加文本框的大小,以便用户的文本不会被截断。我还想将按钮上显示的文本从默认的“运行交互”更改为自定义内容。

我已经广泛阅读了文档并在网上查看,但我找不到一个代码示例来说明如何为交互/交互手动函数设置任何类型的格式。

有什么办法可以改变文本框的大小以及设置小部件其他属性的格式吗?

python jupyter-notebook widget jupyter ipywidgets
1个回答
0
投票

要点是您可以将特定的小部件传递到交互、交互和交互手动调用中。因此,您可以像我一样控制文本框宽度here

这是

interact()
的示例:

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

text_input = widgets.Text(
        value="",
        description="Enter text here:",
        style={"description_width": "initial"},
        layout=widgets.Layout(width='70%'), 
    )

def f(x):
    return x

interact(f, x=text_input);

这也适用于

interact_manual()

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

text_input = widgets.Text(
        value="",
        description="Enter text here:",
        style={"description_width": "initial"},
        layout=widgets.Layout(width='70%'), 
    )

def f(x):
    return x

interact_manual(f, x=text_input);

我需要更长的时间来添加

interact_manual()
用法,因为我不习惯使用该用法。 这里虽然是方法,但我相信。

© www.soinside.com 2019 - 2024. All rights reserved.