Kivy - 在标签按钮上添加一个图标 [英] Kivy - Add an icon to tab buttons
问题描述
我在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.
现在我有这样的事情:
Right now I have something like this :
我希望这样的话:
And I would like something like that :
我的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。将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
,你将添加图片背景矩形
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 - 在标签按钮上添加一个图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!