获取 kivy 的 ReferenceListProperty 的 NumericProperty

2024-09-28 05:26:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些代码:

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

C = ReferenceListProperty(A, B)

我怎样才能取回ReferenceListProperty的NumericProperty?在


Tags: 代码numericpropertyreferencelistproperty
1条回答
网友
1楼 · 发布于 2024-09-28 05:26:48

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

下面是一个小的示例应用程序,它从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()

相关问题 更多 >

    热门问题