【发布时间】:2020-08-20 02:48:12
【问题描述】:
对于我在 ipyvolume 中制作的模型的图例,我想制作一个 widget.HTML,它在 widgets.HTML() 中的相应标签之外显示一个小颜色框。
正如我所见,您只能为 html 代码放置一个字符串行。有人有好主意吗?
【问题讨论】:
标签: python html css jupyter-notebook ipywidgets
对于我在 ipyvolume 中制作的模型的图例,我想制作一个 widget.HTML,它在 widgets.HTML() 中的相应标签之外显示一个小颜色框。
正如我所见,您只能为 html 代码放置一个字符串行。有人有好主意吗?
【问题讨论】:
标签: python html css jupyter-notebook ipywidgets
我决定只用想要的颜色构建一个网格和颜色按钮:
def create_expanded_button(description):
return Button(description=description, style={'font_weight': 'bold'}, layout=Layout( width='auto'))
def color_box (description, color):
b1 = Button(description=description)
b1.style.button_color = color
return b1
# names and colors are two lists of length 11 and 22
cgrid = GridspecLayout(12, 2)
tgrid = GridspecLayout(12, 1)
c = 0
for i in range(12):
for j in range(2):
cgrid[i, j] = color_box(''.format(i, j), colors[c])
c+=1
for i in range(12):
for j in range(1):
tgrid[i, j] = create_expanded_button(names[i-1].format(i, j))
grid = GridspecLayout(2, 2, height='auto', width='auto')
grid[:, :1] = cgrid
grid[:, 1:] = tgrid
grid
【讨论】: