如何解决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 举报,一经查实,本站将立刻删除。