【问题标题】:How to get Kivy id如何获得 Kivy id
【发布时间】:2021-11-04 16:19:28
【问题描述】:

我刚开始学习 kivy,我尝试创建 2 个屏幕的应用程序

现在我有 AttributeError:

box = self.ids.box 文件“kivy/properties.pyx”,第 864 行,在 kivy.properties.ObservableDict.getattr AttributeError:“超级”对象没有属性“getattr

我的 .kv 文件


WindowManager:
    FirstWindow:
    SecondWindow:


<FirstWindow>:
    name: "first"

    MDRoundFlatButton:
            text: "LOG IN"
            font_size: 12
            pos_hint: {"center_x": 0.5}
            on_release:
                app.root.current = "second"
                
                root.manager.transition.direction = "left"


<SecondWindow>:
    name: "second"
    BoxLayout:
        orientation: "vertical"
        size: root.width, root.height
        GridLayout:
            cols: 2
            GridLayout:
                cols: 2

                Label:
                    text: "Watchlist Screen"
                    font_size: 32

                BoxLayout:
                    id: box
                    size_hint_y: .8
                    pos_hint: {"top":1}

id box应该怎么称呼

lass AwesomeApp(MDApp):
    def __init__(self, **kwargs):

        super().__init__(**kwargs)

    def build(self):
        return Builder.load_file('login.kv')

class FirstWindow(Screen):
    pass

class SecondWindow(Screen):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        x = [1, 2, 3, 4, 5]
        y = [5, 12, 6, 9, 15]

        plt.plot(x, y)
        plt.ylabel("This is MY Y Axis")
        plt.xlabel("X Axis")
        
        
        box = self.ids.box
        box.add_widget(FigureCanvasKivyAgg(plt.gcf()))


class WindowManager(ScreenManager):
    pass

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

有没有关于 Kivy 的好书?

【问题讨论】:

    标签: python kivy kivymd


    【解决方案1】:

    你可以通过

    获取id
    self.ids.<your_id>
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 2011-11-24
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多