kivy/kivymd 将项目添加到列表时出现问题

发布于 2025-01-09 06:27:03 字数 1372 浏览 1 评论 0原文

我想从文件中读取数据并将其放入 ScrollView 中的标签中,我发现了这样的内容:

    for name in self.list_of_medicine_global_variable:
        screen.ids.widget_of_list.add_widget(
            MDLabel(
                text=name_theme,
                halign="center",
                theme_text_color=name_theme,
            )
        )

但我不知道要放什么而不是“screen.ids...”。我只知道,那么应该是“widget_of_list”,因为这是 id

这是我的代码的重要部分:

class NewMedicineWindow(Screen):
    pass

class MainWindow(Screen):
    pass


class WindowManager(ScreenManager):
   pass


class UtdApp(MDApp):
    name = StringProperty("")
    date = StringProperty("")
    month = StringProperty("")
    year = StringProperty("20")
    used = True
    added_medicine = ""
    list_of_medicine_global_variable = ListProperty([])

    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"

我不知道它是否重要,但我想将第一个函数放在 on_start 函数中

,并在我的代码的重要部分下面kivy 文件:

<NewMedicineWindow>:
name:"nmw"

BoxLayout:

    orientation: "vertical"
    size: root.width, root.height

    MDToolbar:
        title: "Up To Date Medicine"
        right_action_items: [["plus", lambda x: app.new_medicine()]]

    ScrollView:

        MDList:
            id: widget_of_list

某人知道如何转换该函数以使其在我的代码中工作吗? 拜托,我完全不知道该怎么办

I want to read data from the file and put it into labels in ScrollView, and I found sth like this:

    for name in self.list_of_medicine_global_variable:
        screen.ids.widget_of_list.add_widget(
            MDLabel(
                text=name_theme,
                halign="center",
                theme_text_color=name_theme,
            )
        )

but I don't know what to put instead of "screen.ids...". I just know that, then should be "widget_of_list" cause this is the id

Here are important parts of my code:

class NewMedicineWindow(Screen):
    pass

class MainWindow(Screen):
    pass


class WindowManager(ScreenManager):
   pass


class UtdApp(MDApp):
    name = StringProperty("")
    date = StringProperty("")
    month = StringProperty("")
    year = StringProperty("20")
    used = True
    added_medicine = ""
    list_of_medicine_global_variable = ListProperty([])

    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"

I dont't know if it is important but I want to put taht first function in on_start function

And below important part of my kivy file:

<NewMedicineWindow>:
name:"nmw"

BoxLayout:

    orientation: "vertical"
    size: root.width, root.height

    MDToolbar:
        title: "Up To Date Medicine"
        right_action_items: [["plus", lambda x: app.new_medicine()]]

    ScrollView:

        MDList:
            id: widget_of_list

Does sb know how to transform that function to make it work in my code?
Please I completely don't know what to do

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文