简体   繁体   English

获取ReferenceListProperty kivy的NumericProperty

[英]Get NumericProperty of ReferenceListProperty kivy

I have some code: 我有一些代码:

A = NumericProperty(1)
B = NumericProperty(2)

C = ReferenceListProperty(A, B)

How I can get NumericProperty of ReferenceListProperty back? 如何获取ReferenceListProperty的NumericProperty?

C[0] returns A and C[1] returns B C[0]返回A, C[1]返回B

Here is a small Example App with your values, which prints A and B from C (.py) 这是一个带有示例值的小型示例应用程序,可从C(.py)打印A和B

from kivy.app import App
from kivy.base import Builder
from kivy.properties import NumericProperty, ReferenceListProperty
from kivy.uix.boxlayout import BoxLayout

Builder.load_string("""
<rootwi>:
    Button:
        text: 'print A via ReferenceListProperty'
        on_press: print(root.C[0])
    Button:
        text: 'print B via ReferenceListProperty'
        on_press: print(root.C[1])
""")
class rootwi(BoxLayout):
    A = NumericProperty(1)
    B = NumericProperty(2)
    C = ReferenceListProperty(A, B)


class MyApp(App):
    def build(self):
        return rootwi()

if __name__ == '__main__':
    MyApp().run()


class MyApp(App):
    def build(self):
        return rootwi()

if __name__ == '__main__':
    MyApp().run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM