Kivy - 为标签按钮添加图标

Kivy - Add an icon to tab buttons(Kivy - 为标签按钮添加图标)
本文介绍了Kivy - 为标签按钮添加图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Kivy 中使用 TabbedPanel,效果很好,但我想稍微自定义一下选项卡按钮并在文本旁边添加一个图标.

I am using a TabbedPanel in Kivy, it works perfectly well, but I would like to customize the tab buttons a bit and add a icon next to the text.

现在我有这样的事情:

我想要这样的东西:

我的kv文件如下:

<KivyMasterPanel>
    do_default_tab: False
    id: MasterPanel
    tab_width: self.size[0]/len(self.tab_list)

    TabbedPanelItem:
        id: tab_A
        text: 'A'

    TabbedPanelItem:
        id: tab_B
        text: 'B'

    TabbedPanelItem:
        id: tab_C
        text: 'C'

有什么我可以用来代替 TabbedPannelItem.text 的东西来放置 BoxLayout 或里面的东西.如果可能的话,我希望能够使用 kv 文件创建我的选项卡,但如果不可能,没问题.

Is there something I can use instead of TabbedPannelItem.text to put a BoxLayout or something inside. If possible I would like to be able to create my tabs using a kv file, but if it is not possible, no problem.

提前感谢大家的帮助.

推荐答案

制作一个自定义 TabbedPanelItem,您将在其中添加带有 Rectangle

Make a custom TabbedPanelItem, where you'll add image background with Rectangle

<TPI@TabbedPanelItem>:
    canvas:
        Rectangle:
            source: <your_img>
            size: self.size
            pos: self.pos

并在您的 KivyMasterPanel

这篇关于Kivy - 为标签按钮添加图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)