来自不同类的kivy引用

2024-04-26 02:24:11 发布

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

请问如何推荐B班的a班学生

Builder.load_string("""
<Main>
do_scroll_x: True
do_scroll_y: False
bar_width: 20
padding: 10
Carousel:
    id: caro_slider
    #direction: 'top'
    padding: 10
    orientation: 'vertical'
    BoxLayout:
        padding: 10
        orientation: 'vertical'
        Label:
            text: "one two three"
        Button:
            text: 'Next'
            background_color: 1, 0.1 ,0.1, 1
            pos_hint: {'right': 1}
            size_hint: None, None
            size: '74sp', '35sp'
            on_press: caro_slider.load_next()
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: "five six seven"
        Button:
            text: "Click me"
            background_color: 1, 0.1 ,0.1, 1
            on_press: root.show_popup_item()
            size_hint: .6, .2
            pos_hint: {'center_x': 0.5, 'bottom': 1}
        BoxLayout:
            orientation: 'horizontal'
            size_y: '35sp'
            size_hint: 1, 0
            Button:
                text: 'Previous'
                pos_hint: {'left': 1}
                size_hint: None, None
                size: '74sp', '35sp'
                on_press: caro_slider.load_previous()
            Button:
                text: 'Next'
                background_color: 1, 0.1 ,0.1, 1
                pos_hint: {'right': 1}
                size_hint: None, None
                size: '74sp', '35sp'
                on_press: caro_slider.load_next()
    BoxLayout:
        orientation: 'vertical'
        size_hint: 1, None
        Label:
            text: "Please choose your choice"
            size_hint: None, None
        Label:
            text: ''
            size_hint: None, None
        GridLayout:
            orientation: 'horizontal'
            size_hint: 1, None
            rows: 1
            row_force_default: True
            row_default_height: '35sp'
            CheckBox:
                id: chk_box_4
                height: '35sp'
                group: root.group_list
                size_hint: None, None
                on_active: root.chk_chk(self)
            Label:
                text: "Four over there"
                height: '35sp'
                size_hint: None, None
        Button:
            text: 'Previous'
            background_color: 1, 0.1 ,0.1, .5
            pos_hint: {'left': 1}
            size_hint: None, None
            size: '74sp', '35sp'
            on_press: caro_slider.load_previous()

# the popup
<Pops>
    title: "Welcome!"
    auto_dismiss: False
    background_color: 0.1, 0.1 , 0.8, 0.9
    size: 400, 250
    size_hint: None, None
    title_height: '40sp'
    separator_height: '1sp'
    separator_color: 1,1,1,1
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: "Thanks and praises"
            id: sub_title
            max_lines: 5
            size_hint: None, None
            pos_hint: {'center_y': 0, 'center_x': 0}
        Label:
            id: composition
            text: "Thanks be to GOD for this to [ref=work]work[/ref] and not to work."
            markup: True
            size_x: self.parent.size[0]
            on_ref_press: print 'clicked the link', self.ids.caro_slider.slides     ------> here is the problem
        Button:
            id: close_button
            text: "Click to close"
            background_color: 1, 0.1 ,0.1, 1
            size_hint: .5, .5
            pos_hint: {'center_x': 0.5}
            on_press: root.dismiss()
""")

Tags: textposnonesizeonloadbuttonlabel
1条回答
网友
1楼 · 发布于 2024-04-26 02:24:11

您需要从类B中引用类A。一种简单的通用方法是将引用存储在应用程序类中(即App.get_running_app().classa = a),然后用App.get_running_app().classa引用它。在特定的情况下,可能有更好的地方来放置它,而不是把你的应用搞得一团糟,例如在两个类实例的公共父类中。在

相关问题 更多 >