【发布时间】:2020-04-15 00:46:44
【问题描述】:
我希望能够从 .py 文件向我的滚动列表中添加一行。我想将每一行创建为一个对象,这样它就可以拥有像“user_id”这样的数据,它拥有但不显示(也可以采用不同的方法)。另外,请记住,滚动布局是在清除屏幕中创建的。请帮忙。我真的需要它。
来自我的screens.py:
class PurgeScreen(Screen):
def backButton(self):
SCREEN_MANAGER.current = 'dashboard'
class ListRow(PurgeScreen):
def __init__(self, username, userid, profile_pic):
self.username = username
self.userid = userid
self.profile = profile_pic
def create_row(self):
layout = GridLayout(row=1, row_force_default=True, row_default_height=40)
layout.add_widget(Label(text=self.username))
# Im going to add more stuff in the future
self.ids.widget_list.add_widget(layout)
来自我的 purge.kv:
<PurgeScreen>:
name: 'purge'
FloatLayout:
size_hint: None, None
ScrollView:
size_hint: (None, None)
do_scroll_x: False
bar_width: 4
bar_inactive_color: (.7, .7, .7, .4)
size: (root.width * .75, root.height * .65)
x: (root.width * .5) - (self.width/2)
y: root.height * 0.2
GridLayout:
id: widget_list
cols: 1
size_hint_y: 2
height: self.minimum_height
Button:
text: "1"
Button:
text: "2"
Button:
text: "3"
Button:
text: "4"
【问题讨论】:
-
如果将
create_row()方法移到PurgeScreen类中,它应该可以工作。
标签: python oop kivy grid-layout kivy-language