散景通知段落小部件 - 无法插入换行符

时间:2018-01-13 10:12:49

标签: python bokeh paragraph

在bokeh / python中,我试图让Paragraph小部件像输出控制台一样。所以我定期更新其文本。但是我似乎无法在该框中插入换行符。这意味着控制台几乎不可读。这是一个最小的例子:

from bokeh.io import curdoc
from bokeh.models.widgets import Paragraph, Button
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure

notifications = Paragraph(text='initial text')#, name=name, width=width, height=height)
button = Button(label="Click me to add text")
def callback():
    notifications.text += 'more text' + '\n'
button.on_click(callback)

# Set up layout and add to document
box = widgetbox(notifications, button)
curdoc().add_root(row(box))

' \ n'在行

notifications.text += 'more text' + '\n'

什么都不做,无论是否存在。我也试过了

notifications.text += 'more text' + '<br />'

如果在这里解释html,它不起作用。我还能尝试什么?

1 个答案:

答案 0 :(得分:2)

我建议使用支持HTML的Div小部件,请参阅https://bokeh.pydata.org/en/latest/docs/reference/models/widgets.markups.html#bokeh.models.widgets.markups.Div

然后你的例子变成:

from bokeh.io import curdoc
from bokeh.models.widgets import Div, Button
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure

notifications = Div(text='initial text')#, name=name, width=width, height=height)
button = Button(label="Click me to add text")
def callback():
    notifications.text += 'more text' + '</br>'
button.on_click(callback)

# Set up layout and add to document
box = widgetbox(notifications, button)
curdoc().add_root(row(box))