You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kivy多列RecycleView实现时FinalList类无法识别属性变量问题求助

问题根因

你绑定属性的路径错误,同时没有在Python类中提前声明KV需要用到的属性:

  1. app.root指向的是你的MainWidget实例,它没有定义spalte1_SP等三个属性,这三个属性是FinalList类自己的属性
  2. Kivy中要在KV里使用自定义类的属性,必须提前在Python对应的类中声明对应类型的Kivy属性,否则无法被识别绑定

修复步骤

  1. 首先修改Python代码里的FinalList类,声明三个字符串属性:
class FinalList(BoxLayout):
    spalte1_SP = StringProperty('')
    spalte2_SP = StringProperty('')
    spalte3_SP = StringProperty('')
  1. 然后修改KV文件里FinalList的Label绑定规则,把app.root换成root(在<FinalList>的KV规则里,root就指代当前FinalList实例本身):
<FinalList>:
    orientation: 'horizontal'
    Label:
        id: SP1
        text: root.spalte1_SP
    Label:
        id: SP2
        text: root.spalte2_SP
    Label:
        id: SP3
        text: root.spalte3_SP

修改完成后重新运行即可正常渲染多列列表,RV的data字段里的键值会自动映射到每个FinalList实例的对应属性上,完成列表渲染。

补充小问题:你KV里MaterialS的padding属性拼写错误写成了pading,如果需要生效内边距可以修正拼写。

内容的提问来源于stack exchange,提问作者Batuhan Karakaya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 08:48:05