How to access some widget attribute from another widget in Kivy?

后端 未结 1 1245
甜味超标
甜味超标 2021-01-25 04:06

Ok let\'s say I want that label in some widget to use text from label inside another widget:

:
    Label:
        text: str(root.         


        
1条回答
  •  无人共我
    2021-01-25 04:53

    1. The object property l probably gets populated after the first event loop iteration, while you are trying to access it within the first. You could delay it till the second iteration to make it work.

    2. The most powerful approach is to bind those properties from inside python code, but there are some kv lang tricks to make it simpler. This is my favorite method:

    BoxLayout
    
        Label
            id: label
            text: 'hello world'
    
        SubWidget
            label_text: label.text
    
    
        label_text: 'none'
    
        Label
            text: root.label_text
    

    0 讨论(0)
提交回复
热议问题