我正在尝试访问main.py中的id:container,但似乎找不到正确的输入。这是我的main.py
class ScreenFive(Screen):
def on_start(self):
for i in range(20):
self.ids.screen_manager2.classes.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
这是我的main.kv文件
<ScreenFive>
name: 'home'
FitImage:
source: 'Media/home_bg.png'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: 'QR Attendance'
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
elevation:5
Widget:
NavigationLayout:
ScreenManager:
id: screen_manager2
Screen:
name: 'classes'
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
size: "280dp", "400dp"
pos_hint: {"center_x": .5, "center_y": .5}
ripple_behavior: True
focus_behavior: True
md_bg_color: self.theme_cls.bg_light
ScrollView:
MDList:
id: container
我应该怎么做才能在屏幕“类”中访问MDList?谢谢。
答案 0 :(得分:0)
假设您<ScreenFive>:
中kv
之后的所有内容都缩进了(所以都在ScreenFive
内),那么我认为您可以替换:
self.ids.screen_manager2.classes.container
具有:
self.ids.container