kivy/kivymd 将项目添加到列表时出现问题
我想从文件中读取数据并将其放入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论