Bokeh TextInput在同一行中显示标题和输入框

2024-03-28 15:12:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将TextInput的标题与输入框内联显示,但默认情况下,它显示在两个单独的行上

下面的代码在Jupyter笔记本中创建了一个文本输入框,但它在框上方显示了标题。如何使标题显示在与输入框相同的行上

from bokeh.layouts import column, row
from bokeh.models.widgets import Slider, TextInput
from bokeh.plotting import ColumnDataSource, figure, output_file, show, reset_output, output_notebook

reset_output()
output_notebook()

layout = row([TextInput(title='my label:', value='something')])

show(layout)

电流输出:

所需输出:


Tags: 代码fromimport标题outputshowbokeh情况
1条回答
网友
1楼 · 发布于 2024-03-28 15:12:57

似乎没有可以更改标题位置的设置,但您可以通过在外部小部件(如段落)上写入标题并在TextInput中保留title参数为空来实现类似的结果:

from bokeh.layouts import column, row
from bokeh.models import Paragraph
from bokeh.models.widgets import Slider, TextInput
from bokeh.plotting import ColumnDataSource, figure, output_file, show, reset_output, output_notebook

reset_output()
output_notebook()

title_ = Paragraph(text='my label', align='center')
layout = row([title_, TextInput(title='', value='something')])

show(layout)

输出:

enter image description here

相关问题 更多 >