Python 使用VBox的Bokeh小部件间距和对齐

Python 使用VBox的Bokeh小部件间距和对齐,python,plot,menu,bokeh,hbox,Python,Plot,Menu,Bokeh,Hbox,我一直在使用Bokeh进行绘图,现在需要在绘图中添加菜单以显示不同的输出。菜单是使用上的示例创建的 然后我将这些菜单放在HBox中: menu_bar = HBox(children = [dropdown, dropdown2]) 通过这种方法,可以找到结果页面的布局。菜单栏靠得太近了。我有两个问题: 1) 如何确保菜单之间有一定的空间 2) 如何更改对象的对齐方式?例如,是否可以将小部件对齐在框的右侧而不是左侧 非常感谢。覆盖我对你的问题所说的css 1)我添加了右边距:40px .b

我一直在使用Bokeh进行绘图,现在需要在绘图中添加菜单以显示不同的输出。菜单是使用上的示例创建的

然后我将这些菜单放在HBox中:

menu_bar = HBox(children = [dropdown, dropdown2])
通过这种方法,可以找到结果页面的布局。菜单栏靠得太近了。我有两个问题:

  • 1) 如何确保菜单之间有一定的空间
  • 2) 如何更改对象的对齐方式?例如,是否可以将小部件对齐在框的右侧而不是左侧

非常感谢。

覆盖我对你的问题所说的css 1)我添加了
右边距:40px

.bk-bs-btn-group, .bk-bs-btn-group-vertical {
    display: inline-block;
    margin-right: 40px;
    position: relative;
    vertical-align: middle;
}

您可以将每个
下拉列表
放在
VBox
中,并指定
宽度
高度
。例如:

from bokeh.models.widgets import Dropdown, VBox

menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3","item_3")]
dropdown = Dropdown(label="Dropdown button", type="warning", menu=menu)
dropdown2 = Dropdown(label="Dropdown button2", type="warning", menu=menu)

# put them into boxes and specify their width/height
dropdown_box = VBox(dorpdown, width=100, height=50)
dropdown2_box = VBox(dorpdown2, width=100, height=50)

menu_bar = HBox(children = [dropdown_box, dropdown2_box])

谢谢你的回复。如果没有pythonic的方法,我会用这个:)我认为没有可能,起初,我认为传递宽度和高度参数可以完成这项工作,但这确实是一个边距问题,我看不到在python代码中传递它的方法。如何覆盖bokeh小部件上的css?您可以将每个
下拉列表
放在HBox中,并指定每个HBox的
宽度
高度
。然后,您可以将HBox作为子对象传递到菜单栏。我没有进行测试,但应该注意,VBox和HBox已被弃用
from bokeh.models.widgets import Dropdown, VBox

menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3","item_3")]
dropdown = Dropdown(label="Dropdown button", type="warning", menu=menu)
dropdown2 = Dropdown(label="Dropdown button2", type="warning", menu=menu)

# put them into boxes and specify their width/height
dropdown_box = VBox(dorpdown, width=100, height=50)
dropdown2_box = VBox(dorpdown2, width=100, height=50)

menu_bar = HBox(children = [dropdown_box, dropdown2_box])