【问题标题】:Python ipywidgets ToggleButton Style ColorPython ipywidgets 切换按钮样式颜色
【发布时间】:2021-08-03 21:43:43
【问题描述】:

我想更改 ipywidget ToggleButton 的按钮颜色。 在文档中它被描述为:

widgets.ToggleButtons(
    options=['Slow', 'Regular', 'Fast'],
    description='Speed:',
    disabled=False,
    button_style='', # 'success', 'info', 'warning', 'danger' or ''
    tooltips=['Description of slow', 'Description of regular', 'Description of fast'],
#   icons=['check'] * 3
)

我能看到的唯一方法是使用 button_style,但它只有在代码中看到的预定义选项。 有没有办法用自定义按钮颜色自己定义这样的预设? 我还尝试使用 CSS 对其进行样式设置。 button_color、description_color 和 background_color 都不起作用。

我无法将切换按钮颜色更改为预定义配色方案(“成功”、“信息”、“警告”、“危险”或“”)以外的任何颜色。也跳进包里,我没有找到它们是在哪里定义的。这就是为什么我无法覆盖它们。

另外,我正在使用 Jupyter Notebook。

亲切的问候, 蒂莫

【问题讨论】:

    标签: python jupyter-notebook ipywidgets


    【解决方案1】:

    小部件有一个 style 属性,可以帮助您实现您想要的,在此处阅读更多信息:

    https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html#The-style-attribute

    属性会因小部件类型而异。不幸的是,ToggleButtons 的 keys 选项没有列出 button_color,因此看起来不能通过这种方式修改颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 2013-06-07
      • 2017-02-07
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多