Kivy-如何根据小部件ID更改RoundedRectangle源图像?

问题描述

我正在尝试为RoundedRectangle创建规则,其中根据父ID为每个实例选择背景图像。但是,下面的.kv代码仅显示没有背景图像的空白画布。

<Plants_Screen>
name: 'Plants_Screen'
id: Plants_Screen

ScrollView:
    size_hint: (1,1)
    MDList:
        id: plants_list
        elevation: 10
        orientation: 'vertical'
        spacing: '10dp'
        padding: '5dp'

        Plants_List_Item:                      #MDCard class defined in .py
            id: carrots_1
            orientation: 'vertical'

            MDBoxLayout:
                orientation: 'horizontal'
                size_hint: (1,0.4)
                md_bg_color: (0,0.4)
                radius:[15]
                border_radius:15

                MDSeparator:
                    size_hint_x: .1

                MDLabel:
                    text: 'Carrots'
                    theme_text_color: 'Custom'
                    text_color: 1,1,1




<Plants_List_Item>
    size_hint: (None,None)
    height: '120dp'
    width: '500dp'
    orientation: 'vertical'
    radius:[15]
    border_radius:15
    canvas:
        RoundedRectangle:
            radius: [15,]
            source: 'Resources/Images/{}.jpg'.format(id)
            pos: self.pos
            size: self.size

    MDLabel:
        size_hint_y: 0.6
        text: ''

将会有许多Plants_List_Item小部件实例,每个实例具有不同的背景图像。我试图避免必须为Plants_List_Item的每个实例定义画布-> RoundedRectangle->大小,pos等。作为参考,每种背景的图像库都以与小部件的ID相匹配的方式命名。即id:carrots_1来源:“ carrots_1.jpg”

不确定为什么图片不显示!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...